|
| 1 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 2 | +import * as path from 'path'; |
| 3 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 4 | + |
| 5 | +test('adds DTL to devDependencies', async () => { |
| 6 | + const tree = await setup({}); |
| 7 | + const pkg = tree.readContent('package.json'); |
| 8 | + |
| 9 | + expect(pkg).toMatchInlineSnapshot(` |
| 10 | + "{ |
| 11 | + \\"devDependencies\\": { |
| 12 | + \\"@testing-library/dom\\": \\"^10.0.0\\" |
| 13 | + } |
| 14 | + }" |
| 15 | + `); |
| 16 | +}); |
| 17 | + |
| 18 | +test('ignores if DTL is already listed as a dev dependency', async () => { |
| 19 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 20 | + const tree = await setup({ devDependencies: { '@testing-library/dom': '^9.0.0' } }); |
| 21 | + const pkg = tree.readContent('package.json'); |
| 22 | + |
| 23 | + expect(pkg).toMatchInlineSnapshot(`"{\\"devDependencies\\":{\\"@testing-library/dom\\":\\"^9.0.0\\"}}"`); |
| 24 | +}); |
| 25 | + |
| 26 | +test('ignores if DTL is already listed as a dependency', async () => { |
| 27 | + // eslint-disable-next-line @typescript-eslint/naming-convention |
| 28 | + const tree = await setup({ dependencies: { '@testing-library/dom': '^11.0.0' } }); |
| 29 | + const pkg = tree.readContent('package.json'); |
| 30 | + |
| 31 | + expect(pkg).toMatchInlineSnapshot(`"{\\"dependencies\\":{\\"@testing-library/dom\\":\\"^11.0.0\\"}}"`); |
| 32 | +}); |
| 33 | + |
| 34 | +async function setup(packageJson: object) { |
| 35 | + const collectionPath = path.join(__dirname, '../migrations.json'); |
| 36 | + const schematicRunner = new SchematicTestRunner('schematics', collectionPath); |
| 37 | + |
| 38 | + const tree = new UnitTestTree(new EmptyTree()); |
| 39 | + tree.create('package.json', JSON.stringify(packageJson)); |
| 40 | + |
| 41 | + await schematicRunner.runSchematic(`atl-add-dtl-as-dev-dependency`, {}, tree); |
| 42 | + |
| 43 | + return tree; |
| 44 | +} |
0 commit comments