import {Flow as FlowDefinition} from '@chix/common' import {expect} from 'chai' import * as path from 'path' import 'should' import {NPMLoader} from '../src/npm' import {loadGraph} from './util' const testOptions = { paths: [ path.resolve(__dirname, '../../../'), // lerna root ], } describe('NPM Loader:', () => { let loader: NPMLoader let graph: FlowDefinition before(() => { loader = new NPMLoader(testOptions) }) it('Should not have a default provider', () => { loader.should.not.have.property('defaultProvider') }) it('The graph fixture itself should be correct', () => { graph = loadGraph('npm') as FlowDefinition graph.should.not.have.property('providers') expect(graph.nodes).to.be.an('array') expect(graph.nodes[0]).to.not.have.property('provider') expect(graph.nodes[1]).to.not.have.property('provider') }) // this asumes chix-test is installed as dev dependency it('Should be able to load @ definitions', async () => { let result result = await loader.load(graph) const {nodeDefinitions} = result nodeDefinitions.should.be.ok nodeDefinitions.should.have.property('@') nodeDefinitions['@'].should.have.property('test') nodeDefinitions['@'].test.should.have.property('Repeat') nodeDefinitions['@'].test.should.have.property('Drop') loader.hasNodeDefinition('@', 'test', 'Repeat').should.be.ok loader.hasNodeDefinition('@', 'test', 'Drop').should.be.ok /* add several other nodes to test/ which does include this stuff. result.should.have.property('dependencies') result.dependencies.should.eql({ npm: { bogus: '0.x.x' } }) */ result = await loader.loadNodeDefinitionFrom('@', 'test', 'Repeat') /* const expected = { npm: { bogus: '0.x.x' } } */ result.dependencies.should.eql({}) result = await loader.loadNodeDefinitionFrom('@', 'test', 'Drop') result.nodeDefinition.ns.should.eql('test') result.nodeDefinition.name.should.equal('Drop') result.dependencies.should.eql({}) }) it('Should be able to preload providers', async () => { const npmLoader = new NPMLoader(testOptions) const {provider, nodeDefinitions} = await npmLoader.preload() provider.should.eql('@') nodeDefinitions.should.equal(loader.getNodeDefinitions('@')) }) })