diff --git a/packages/ng-schematics/src/schematics/e2e/index.ts b/packages/ng-schematics/src/schematics/e2e/index.ts index 8316b9bc..2a874716 100644 --- a/packages/ng-schematics/src/schematics/e2e/index.ts +++ b/packages/ng-schematics/src/schematics/e2e/index.ts @@ -55,6 +55,10 @@ function parseUserTestArgs(userArgs: Record): SchematicsSpec { options['route'] = userArgs['n']; } + if (options['route'] && !options['route'].startsWith('/')) { + options['route'] = `/${options['route']}`; + } + return options as SchematicsSpec; } diff --git a/packages/ng-schematics/test/src/e2e.spec.ts b/packages/ng-schematics/test/src/e2e.spec.ts index f5c989df..3b6677ad 100644 --- a/packages/ng-schematics/test/src/e2e.spec.ts +++ b/packages/ng-schematics/test/src/e2e.spec.ts @@ -26,6 +26,30 @@ describe('@puppeteer/ng-schematics: e2e', () => { expect(tree.files).not.toContain('/e2e/tests/my-test.e2e.ts'); expect(tree.files).toContain('/e2e/tests/my-test.test.ts'); }); + + it('should create file with route', async () => { + const route = 'home'; + const tree = await buildTestingTree('e2e', 'single', { + name: 'myTest', + route, + }); + expect(tree.files).toContain('/e2e/tests/my-test.e2e.ts'); + expect(tree.readContent('/e2e/tests/my-test.e2e.ts')).toContain( + `setupBrowserHooks('/${route}');` + ); + }); + + it('should create with route with starting slash', async () => { + const route = '/home'; + const tree = await buildTestingTree('e2e', 'single', { + name: 'myTest', + route, + }); + expect(tree.files).toContain('/e2e/tests/my-test.e2e.ts'); + expect(tree.readContent('/e2e/tests/my-test.e2e.ts')).toContain( + `setupBrowserHooks('${route}');` + ); + }); }); describe('Multi projects', () => { @@ -53,5 +77,33 @@ describe('@puppeteer/ng-schematics: e2e', () => { getMultiProjectFile('e2e/tests/my-test.test.ts') ); }); + + it('should create file with route', async () => { + const route = 'home'; + const tree = await buildTestingTree('e2e', 'multi', { + name: 'myTest', + route, + }); + expect(tree.files).toContain( + getMultiProjectFile('e2e/tests/my-test.e2e.ts') + ); + expect( + tree.readContent(getMultiProjectFile('e2e/tests/my-test.e2e.ts')) + ).toContain(`setupBrowserHooks('/${route}');`); + }); + + it('should create with route with starting slash', async () => { + const route = '/home'; + const tree = await buildTestingTree('e2e', 'multi', { + name: 'myTest', + route, + }); + expect(tree.files).toContain( + getMultiProjectFile('e2e/tests/my-test.e2e.ts') + ); + expect( + tree.readContent(getMultiProjectFile('e2e/tests/my-test.e2e.ts')) + ).toContain(`setupBrowserHooks('${route}');`); + }); }); }); diff --git a/packages/ng-schematics/tools/sandbox.js b/packages/ng-schematics/tools/sandbox.mjs similarity index 80% rename from packages/ng-schematics/tools/sandbox.js rename to packages/ng-schematics/tools/sandbox.mjs index b6178f03..88170e7c 100644 --- a/packages/ng-schematics/tools/sandbox.js +++ b/packages/ng-schematics/tools/sandbox.mjs @@ -14,15 +14,16 @@ * limitations under the License. */ -const {spawn} = require('child_process'); -const {readFile, writeFile} = require('fs/promises'); -const {join} = require('path'); -const {cwd} = require('process'); +import {spawn} from 'child_process'; +import {readFile, writeFile} from 'fs/promises'; +import {join} from 'path'; +import {cwd} from 'process'; const isInit = process.argv.indexOf('--init') !== -1; const isMulti = process.argv.indexOf('--multi') !== -1; const isBuild = process.argv.indexOf('--build') !== -1; -const isTest = process.argv.indexOf('--test') !== -1; +const isE2E = process.argv.indexOf('--e2e') !== -1; +const isConfig = process.argv.indexOf('--config') !== -1; const commands = { build: ['npm run build'], createSandbox: ['npx ng new sandbox --defaults'], @@ -51,9 +52,17 @@ const commands = { }, }, ], - runSchematicsTest: [ + runSchematicsE2E: [ { - command: 'npm run schematics:test', + command: 'npm run schematics:e2e', + options: { + cwd: join(cwd(), '/sandbox/'), + }, + }, + ], + runSchematicsConfig: [ + { + command: 'npm run schematics:config', options: { cwd: join(cwd(), '/sandbox/'), }, @@ -69,8 +78,10 @@ const scripts = { // Runs the Puppeteer Ng-Schematics against the sandbox schematics: 'npm run delete:file && npm run build:schematics && schematics ../:ng-add --dry-run=false', - 'schematics:test': - 'npm run build:schematics && schematics ../:test --dry-run=false', + 'schematics:e2e': + 'npm run build:schematics && schematics ../:e2e --dry-run=false', + 'schematics:config': + 'npm run build:schematics && schematics ../:config --dry-run=false', }; /** * @@ -134,9 +145,13 @@ async function main() { if (isBuild) { await executeCommand(commands.build); } - await executeCommand( - isTest ? commands.runSchematicsTest : commands.runSchematics - ); + if (isE2E) { + await executeCommand(commands.runSchematicsE2E); + } else if (isConfig) { + await executeCommand(commands.runSchematicsConfig); + } else { + await executeCommand(commands.runSchematics); + } } }