|
| 1 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing' |
| 2 | +import { expect } from 'chai' |
| 3 | +import { join } from 'path' |
| 4 | + |
| 5 | +describe('ng-generate @cypress/schematic:component', () => { |
| 6 | + const schematicRunner = new SchematicTestRunner( |
| 7 | + 'schematics', |
| 8 | + join(__dirname, '../../collection.json'), |
| 9 | + ) |
| 10 | + let appTree: UnitTestTree |
| 11 | + |
| 12 | + const workspaceOptions = { |
| 13 | + name: 'workspace', |
| 14 | + newProjectRoot: 'projects', |
| 15 | + version: '12.0.0', |
| 16 | + } |
| 17 | + |
| 18 | + const appOptions: Parameters<typeof schematicRunner['runExternalSchematicAsync']>[2] = { |
| 19 | + name: 'sandbox', |
| 20 | + inlineTemplate: false, |
| 21 | + routing: false, |
| 22 | + skipTests: false, |
| 23 | + skipPackageJson: false, |
| 24 | + } |
| 25 | + |
| 26 | + beforeEach(async () => { |
| 27 | + appTree = await schematicRunner.runExternalSchematicAsync('@schematics/angular', 'workspace', workspaceOptions).toPromise() |
| 28 | + appTree = await schematicRunner.runExternalSchematicAsync('@schematics/angular', 'application', appOptions, appTree).toPromise() |
| 29 | + }) |
| 30 | + |
| 31 | + it('should create cypress ct alongside the generated component', async () => { |
| 32 | + const tree = await schematicRunner.runSchematicAsync('component', { name: 'foo', project: 'sandbox' }, appTree).toPromise() |
| 33 | + |
| 34 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/foo.component.ts') |
| 35 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/foo.component.html') |
| 36 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/foo.component.cy.ts') |
| 37 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/foo.component.css') |
| 38 | + expect(tree.files).not.to.contain('/projects/sandbox/src/app/foo/foo.component.spec.ts') |
| 39 | + }) |
| 40 | + |
| 41 | + it('should not generate component which does exist already', async () => { |
| 42 | + let tree = await schematicRunner.runSchematicAsync('component', { name: 'foo', project: 'sandbox' }, appTree).toPromise() |
| 43 | + |
| 44 | + tree = await schematicRunner.runSchematicAsync('component', { name: 'foo', project: 'sandbox' }, appTree).toPromise() |
| 45 | + |
| 46 | + expect(tree.files.filter((f) => f === '/projects/sandbox/src/app/foo/foo.component.ts').length).to.eq(1) |
| 47 | + expect(tree.files.filter((f) => f === '/projects/sandbox/src/app/foo/foo.component.html').length).to.eq(1) |
| 48 | + expect(tree.files.filter((f) => f === '/projects/sandbox/src/app/foo/foo.component.cy.ts').length).to.eq(1) |
| 49 | + expect(tree.files.filter((f) => f === '/projects/sandbox/src/app/foo/foo.component.css').length).to.eq(1) |
| 50 | + }) |
| 51 | + |
| 52 | + it('should generate component given a component containing a directory', async () => { |
| 53 | + const tree = await schematicRunner.runSchematicAsync('component', { name: 'foo/bar', project: 'sandbox' }, appTree).toPromise() |
| 54 | + |
| 55 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/bar/bar.component.ts') |
| 56 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/bar/bar.component.html') |
| 57 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/bar/bar.component.cy.ts') |
| 58 | + expect(tree.files).to.contain('/projects/sandbox/src/app/foo/bar/bar.component.css') |
| 59 | + }) |
| 60 | +}) |
0 commit comments