Skip to content

Commit

Permalink
feat(angular): add playwright to e2eTestRunner option
Browse files Browse the repository at this point in the history
  • Loading branch information
barbados-clemens committed Jul 18, 2023
1 parent 8d160b2 commit 5a4fdda
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/angular/src/generators/application/application.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 () => {
Expand Down
17 changes: 17 additions & 0 deletions packages/angular/src/generators/application/lib/add-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
});
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/utils/test-runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export enum UnitTestRunner {

export enum E2eTestRunner {
Cypress = 'cypress',
Playwright = 'playwright',
None = 'none',
}
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export {
playwrightExecutor,
PlaywrightExecutorSchema,
} from './executors/playwright/playwright';
export { initGenerator } from './generators/init/init';
export { configurationGenerator } from './generators/configuration/configuration';

0 comments on commit 5a4fdda

Please sign in to comment.