From f5f31ab9798e269a8306dc5a187782c4495c0cf8 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Wed, 25 Oct 2023 16:57:28 -0400 Subject: [PATCH] fix(testing): add e2e for root project should not add eslintrc.base (#19860) --- .../playwright/generators/configuration.json | 7 +++++++ e2e/eslint/src/linter.test.ts | 16 ++++++++++++---- .../src/generators/application/lib/add-e2e.ts | 2 ++ .../generators/configuration/configuration.ts | 3 ++- .../generators/configuration/configuration.ts | 2 +- .../src/generators/configuration/schema.d.ts | 1 + .../src/generators/configuration/schema.json | 7 +++++++ .../src/generators/application/lib/add-e2e.ts | 2 ++ 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/generated/packages/playwright/generators/configuration.json b/docs/generated/packages/playwright/generators/configuration.json index 06e680765409f..dfd95f93b8b54 100644 --- a/docs/generated/packages/playwright/generators/configuration.json +++ b/docs/generated/packages/playwright/generators/configuration.json @@ -56,6 +56,13 @@ "default": false, "description": "Do not add dependencies to `package.json`.", "x-priority": "internal" + }, + "rootProject": { + "description": "Create a application at the root of the workspace", + "type": "boolean", + "default": false, + "hidden": true, + "x-priority": "internal" } }, "required": ["project"], diff --git a/e2e/eslint/src/linter.test.ts b/e2e/eslint/src/linter.test.ts index 1df212e0ec286..5eb0bd798df12 100644 --- a/e2e/eslint/src/linter.test.ts +++ b/e2e/eslint/src/linter.test.ts @@ -680,7 +680,9 @@ describe('Linter', () => { // should have plugin extends expect(appEslint.overrides[0].extends).toBeDefined(); expect(appEslint.overrides[1].extends).toBeDefined(); - expect(e2eEslint.overrides[0].extends).toBeDefined(); + expect( + e2eEslint.overrides.some((override) => override.extends) + ).toBeTruthy(); runCLI(`generate @nx/js:lib ${mylib} --unitTestRunner=jest`); verifySuccessfulMigratedSetup(myapp, mylib); @@ -691,7 +693,9 @@ describe('Linter', () => { // should have no plugin extends expect(appEslint.overrides[0].extends).toBeUndefined(); expect(appEslint.overrides[1].extends).toBeUndefined(); - expect(e2eEslint.overrides[0].extends).toBeUndefined(); + expect( + e2eEslint.overrides.some((override) => override.extends) + ).toBeFalsy(); }); it('(Angular standalone) should set root project config to app and e2e app and migrate when another lib is added', () => { @@ -708,7 +712,9 @@ describe('Linter', () => { // should have plugin extends expect(appEslint.overrides[1].extends).toBeDefined(); - expect(e2eEslint.overrides[0].extends).toBeDefined(); + expect( + e2eEslint.overrides.some((override) => override.extends) + ).toBeTruthy(); runCLI(`generate @nx/js:lib ${mylib} --no-interactive`); verifySuccessfulMigratedSetup(myapp, mylib); @@ -720,7 +726,9 @@ describe('Linter', () => { expect(appEslint.overrides[1].extends).toEqual([ 'plugin:@nx/angular-template', ]); - expect(e2eEslint.overrides[0].extends).toBeUndefined(); + expect( + e2eEslint.overrides.some((override) => override.extends) + ).toBeFalsy(); }); it('(Node standalone) should set root project config to app and e2e app and migrate when another lib is added', async () => { diff --git a/packages/angular/src/generators/application/lib/add-e2e.ts b/packages/angular/src/generators/application/lib/add-e2e.ts index 545158e80ad89..a836bd8f67611 100644 --- a/packages/angular/src/generators/application/lib/add-e2e.ts +++ b/packages/angular/src/generators/application/lib/add-e2e.ts @@ -31,6 +31,7 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) { skipPackageJson: options.skipPackageJson, skipFormat: true, devServerTarget: `${options.name}:serve:development`, + rootProject: options.rootProject, }); } else if (options.e2eTestRunner === 'playwright') { const { configurationGenerator: playwrightConfigurationGenerator } = @@ -57,6 +58,7 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) { options.name }`, webServerAddress: `http://localhost:${options.port ?? 4200}`, + rootProject: options.rootProject, }); } } diff --git a/packages/cypress/src/generators/configuration/configuration.ts b/packages/cypress/src/generators/configuration/configuration.ts index 60dc9fff45d9c..fb203b2784957 100644 --- a/packages/cypress/src/generators/configuration/configuration.ts +++ b/packages/cypress/src/generators/configuration/configuration.ts @@ -36,6 +36,7 @@ export interface CypressE2EConfigSchema { linter?: Linter; port?: number | 'cypress-auto'; jsx?: boolean; + rootProject?: boolean; } type NormalizedSchema = ReturnType; @@ -91,7 +92,7 @@ In this case you need to provide a devServerTarget,':[: return { ...options, bundler: options.bundler ?? 'webpack', - rootProject: projectConfig.root === '.', + rootProject: options.rootProject ?? projectConfig.root === '.', linter: options.linter ?? Linter.EsLint, devServerTarget: options.devServerTarget ?? diff --git a/packages/playwright/src/generators/configuration/configuration.ts b/packages/playwright/src/generators/configuration/configuration.ts index 40278071c3aba..b2279bd122362 100644 --- a/packages/playwright/src/generators/configuration/configuration.ts +++ b/packages/playwright/src/generators/configuration/configuration.ts @@ -46,7 +46,7 @@ export async function configurationGenerator( js: options.js, directory: options.directory, setParserOptionsProject: options.setParserOptionsProject, - rootProject: projectConfig.root === '.', + rootProject: options.rootProject ?? projectConfig.root === '.', }) ); diff --git a/packages/playwright/src/generators/configuration/schema.d.ts b/packages/playwright/src/generators/configuration/schema.d.ts index 2701b8ae27bb7..2a33aee4daa17 100644 --- a/packages/playwright/src/generators/configuration/schema.d.ts +++ b/packages/playwright/src/generators/configuration/schema.d.ts @@ -21,4 +21,5 @@ export interface ConfigurationGeneratorSchema { * @example: "http://localhost:4200" **/ webServerAddress?: string; + rootProject?: boolean; } diff --git a/packages/playwright/src/generators/configuration/schema.json b/packages/playwright/src/generators/configuration/schema.json index 1ee30bda86a8f..4e90248727990 100644 --- a/packages/playwright/src/generators/configuration/schema.json +++ b/packages/playwright/src/generators/configuration/schema.json @@ -55,6 +55,13 @@ "default": false, "description": "Do not add dependencies to `package.json`.", "x-priority": "internal" + }, + "rootProject": { + "description": "Create a application at the root of the workspace", + "type": "boolean", + "default": false, + "hidden": true, + "x-priority": "internal" } }, "required": ["project"] diff --git a/packages/react/src/generators/application/lib/add-e2e.ts b/packages/react/src/generators/application/lib/add-e2e.ts index 838fe4ce03ea7..42753920f9a86 100644 --- a/packages/react/src/generators/application/lib/add-e2e.ts +++ b/packages/react/src/generators/application/lib/add-e2e.ts @@ -43,6 +43,7 @@ export async function addE2e( skipFormat: true, devServerTarget: `${options.projectName}:serve`, jsx: true, + rootProject: options.rootProject, }); } case 'playwright': { @@ -68,6 +69,7 @@ export async function addE2e( options.name }`, webServerAddress: 'http://localhost:4200', + rootProject: options.rootProject, }); } case 'none':