|
| 1 | +const mockFs = require('mock-fs'); |
| 2 | +const expect = require('chai').expect; |
| 3 | +import * as path from 'path'; |
| 4 | +import {findLoadChildren, findLazyModules} from 'angular-cli/models/find-lazy-modules'; |
| 5 | + |
| 6 | +describe('find-lazy-modules', () => { |
| 7 | + beforeEach(() => { |
| 8 | + let mockDrive = { |
| 9 | + 'node_modules/feature-module': { |
| 10 | + 'package.json': '{ "main": "index.js" }', |
| 11 | + 'index.js': '' |
| 12 | + }, |
| 13 | + 'src/app': { |
| 14 | + 'app.module.ts': `RouterModule.forRoot([ |
| 15 | + { path: 'relative', loadChildren: './feature-a/feature-a.module' }, |
| 16 | + { path: 'absolute', loadChildren: 'src/app/feature-b/feature-b.module' }, |
| 17 | + { path: 'module', loadChildren: 'feature-module' }, |
| 18 | + { path: 'module2', loadChildren: 'feature-module/index.js' }, |
| 19 | + { path: 'invalid', loadChildren: 'invalid' } |
| 20 | + ]);`, |
| 21 | + 'feature-a': { |
| 22 | + 'feature-a.module.ts': '' |
| 23 | + }, |
| 24 | + 'feature-b': { |
| 25 | + 'feature-b.module.ts': '' |
| 26 | + } |
| 27 | + } |
| 28 | + }; |
| 29 | + mockFs(mockDrive); |
| 30 | + }); |
| 31 | + afterEach(() => { |
| 32 | + mockFs.restore(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should find children', () => { |
| 36 | + let children = findLoadChildren('src/app/app.module.ts'); |
| 37 | + expect(children.length).to.equal(5); |
| 38 | + expect(children.sort()).to.deep.equal([ |
| 39 | + './feature-a/feature-a.module', |
| 40 | + 'feature-module', |
| 41 | + 'feature-module/index.js', |
| 42 | + 'invalid', |
| 43 | + 'src/app/feature-b/feature-b.module' |
| 44 | + ]); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should find lazy modules', () => { |
| 48 | + let modules = findLazyModules('.'); |
| 49 | + expect(modules).to.deep.equal({ |
| 50 | + './feature-a/feature-a.module': |
| 51 | + path.join(__dirname, '../../src/app/feature-a/feature-a.module.ts'), |
| 52 | + 'src/app/feature-b/feature-b.module': |
| 53 | + path.join(__dirname, '../../src/app/feature-b/feature-b.module.ts'), |
| 54 | + 'feature-module': |
| 55 | + path.join(__dirname, '../../node_modules/feature-module/index.js'), |
| 56 | + 'feature-module/index.js': |
| 57 | + path.join(__dirname, '../../node_modules/feature-module/index.js') |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments