|
| 1 | +import { resolve } from 'path'; |
| 2 | +import { AbstractRunner } from '../../../lib/runners'; |
| 3 | +import { CustomCollection } from '../../../lib/schematics/custom.collection'; |
| 4 | + |
| 5 | +describe('Custom Collection', () => { |
| 6 | + it(`should list schematics from simple collection`, async () => { |
| 7 | + const mock = jest.fn(); |
| 8 | + mock.mockImplementation(() => { |
| 9 | + return { |
| 10 | + logger: {}, |
| 11 | + run: jest.fn().mockImplementation(() => Promise.resolve()), |
| 12 | + }; |
| 13 | + }); |
| 14 | + const mockedRunner = mock(); |
| 15 | + const collection = new CustomCollection( |
| 16 | + require.resolve('./fixtures/simple/collection.json'), |
| 17 | + mockedRunner as AbstractRunner, |
| 18 | + ); |
| 19 | + const schematics = collection.getSchematics(); |
| 20 | + expect(schematics).toEqual([ |
| 21 | + { name: 'simple1', alias: 's1', description: 'Simple schematic 1' }, |
| 22 | + { name: 'simple2', alias: 's2', description: 'Simple schematic 2' }, |
| 23 | + { name: 'simple3', alias: 's3', description: 'Simple schematic 3' }, |
| 24 | + ]); |
| 25 | + }); |
| 26 | + |
| 27 | + it(`should list schematics from extended collection`, async () => { |
| 28 | + const mock = jest.fn(); |
| 29 | + mock.mockImplementation(() => { |
| 30 | + return { |
| 31 | + logger: {}, |
| 32 | + run: jest.fn().mockImplementation(() => Promise.resolve()), |
| 33 | + }; |
| 34 | + }); |
| 35 | + const mockedRunner = mock(); |
| 36 | + const collection = new CustomCollection( |
| 37 | + require.resolve('./fixtures/extended/collection.json'), |
| 38 | + mockedRunner as AbstractRunner, |
| 39 | + ); |
| 40 | + const schematics = collection.getSchematics(); |
| 41 | + expect(schematics).toEqual([ |
| 42 | + { name: 'extend1', alias: 'x1', description: 'Extended schematic 1' }, |
| 43 | + { name: 'extend2', alias: 'x2', description: 'Extended schematic 2' }, |
| 44 | + { name: 'simple1', alias: 's1', description: 'Override schematic 1' }, |
| 45 | + { |
| 46 | + name: 'simple2', |
| 47 | + alias: 'os2', |
| 48 | + description: 'Override schematic 2', |
| 49 | + }, |
| 50 | + { |
| 51 | + name: 'simple3', |
| 52 | + alias: 'simple3', |
| 53 | + description: 'Simple schematic 3', |
| 54 | + }, |
| 55 | + ]); |
| 56 | + }); |
| 57 | + |
| 58 | + it(`should list schematics from package with collection.json path in package.json`, async () => { |
| 59 | + const mock = jest.fn(); |
| 60 | + mock.mockImplementation(() => { |
| 61 | + return { |
| 62 | + logger: {}, |
| 63 | + run: jest.fn().mockImplementation(() => Promise.resolve()), |
| 64 | + }; |
| 65 | + }); |
| 66 | + const mockedRunner = mock(); |
| 67 | + const collection = new CustomCollection( |
| 68 | + 'package', |
| 69 | + mockedRunner as AbstractRunner, |
| 70 | + ); |
| 71 | + const schematics = collection.getSchematics(); |
| 72 | + expect(schematics).toEqual([ |
| 73 | + { name: 'package1', alias: 'pkg1', description: 'Package schematic 1' }, |
| 74 | + ]); |
| 75 | + }); |
| 76 | +}); |
0 commit comments