diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index aa9de783ae8ddf..c5722cfc4b6b3b 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -128,6 +128,23 @@ describe('app', () => { expect(tsconfigE2E).toMatchSnapshot('e2e tsconfig.json'); }); + it('should setup playwright', async () => { + await generateApp(appTree, 'playwright-app', { + e2eTestRunner: E2eTestRunner.Playwright, + }); + + expect( + appTree.exists('apps/playwright-app-e2e/playwright.config.ts') + ).toBeTruthy(); + expect( + appTree.exists('apps/playwright-app-e2e/src/example.spec.ts') + ).toBeTruthy(); + expect( + readProjectConfiguration(appTree, 'playwright-app-e2e')?.targets?.e2e + ?.executor + ).toEqual('@nx/playwright:playwright'); + }); + it('should setup jest with serializers', async () => { await generateApp(appTree); @@ -869,6 +886,18 @@ describe('app', () => { const project = readProjectConfiguration(appTree, 'my-app'); expect(project.targets.build.options['outputPath']).toBe('dist/my-app'); }); + + it('should generate playwright with root project', async () => { + await generateApp(appTree, 'root-app', { + e2eTestRunner: E2eTestRunner.Playwright, + rootProject: true, + }); + expect( + readProjectConfiguration(appTree, 'e2e').targets.e2e.executor + ).toEqual('@nx/playwright:playwright'); + expect(appTree.exists('e2e/playwright.config.ts')).toBeTruthy(); + expect(appTree.exists('e2e/src/example.spec.ts')).toBeTruthy(); + }); }); it('should error correctly when Angular version does not support standalone', async () => { diff --git a/packages/angular/src/generators/application/lib/add-e2e.ts b/packages/angular/src/generators/application/lib/add-e2e.ts index 7e60957d8eb543..45ac1931610a89 100644 --- a/packages/angular/src/generators/application/lib/add-e2e.ts +++ b/packages/angular/src/generators/application/lib/add-e2e.ts @@ -2,12 +2,15 @@ import { cypressProjectGenerator } from '@nx/cypress'; import type { Tree } from '@nx/devkit'; import { addDependenciesToPackageJson, + addProjectConfiguration, + joinPathFragments, readProjectConfiguration, updateProjectConfiguration, } from '@nx/devkit'; import { nxVersion } from '../../../utils/versions'; import type { NormalizedSchema } from './normalized-schema'; import { removeScaffoldedE2e } from './remove-scaffolded-e2e'; +import { configurationGenerator } from '@nx/playwright'; export async function addE2e(tree: Tree, options: NormalizedSchema) { removeScaffoldedE2e(tree, options, options.ngCliSchematicE2ERoot); @@ -25,6 +28,20 @@ export async function addE2e(tree: Tree, options: NormalizedSchema) { skipPackageJson: options.skipPackageJson, skipFormat: true, }); + } else if (options.e2eTestRunner === 'playwright') { + addProjectConfiguration(tree, options.e2eProjectName, { + root: options.e2eProjectRoot, + sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), + targets: {}, + implicitDependencies: [options.name], + }); + await configurationGenerator(tree, { + project: options.e2eProjectName, + skipFormat: true, + skipPackageJson: options.skipPackageJson, + directory: 'src', + js: false, + }); } } diff --git a/packages/angular/src/utils/test-runners.ts b/packages/angular/src/utils/test-runners.ts index f0950951f3ef1b..642a233683ef5d 100644 --- a/packages/angular/src/utils/test-runners.ts +++ b/packages/angular/src/utils/test-runners.ts @@ -5,5 +5,6 @@ export enum UnitTestRunner { export enum E2eTestRunner { Cypress = 'cypress', + Playwright = 'playwright', None = 'none', } diff --git a/packages/playwright/src/generators/configuration/configuration.ts b/packages/playwright/src/generators/configuration/configuration.ts index a0c04a8cbd2c97..e1772d50badea6 100644 --- a/packages/playwright/src/generators/configuration/configuration.ts +++ b/packages/playwright/src/generators/configuration/configuration.ts @@ -67,6 +67,7 @@ function addE2eTarget(tree: Tree, options: ConfigurationGeneratorSchema) { throw new Error(`Project ${options.project} already has an e2e target. Rename or remove the existing e2e target.`); } + projectConfig.targets ??= {}; projectConfig.targets.e2e = { executor: '@nx/playwright:playwright', options: {}, diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index 8b96dbdf4ae12a..d404de56a7403e 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -2,3 +2,5 @@ export { playwrightExecutor, PlaywrightExecutorSchema, } from './executors/playwright/playwright'; +export { initGenerator } from './generators/init/init'; +export { configurationGenerator } from './generators/configuration/configuration';