diff --git a/README.md b/README.md index 968f23c..ac2d343 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,19 @@ Once installed, you can run the tests npm run e2e ``` +## Run tests +You can also use `ng` to run your tests +```bash +ng e2e +``` + +Some command-line interface options are available; such as UI mode +```bash +ng e2e --ui +``` + +For a list of accepted arguments, use `ng --help`. If you need more options and control on the CLI, the best solution is to use `npx playwright test` directly. + ## Create a test file Create a new empty test diff --git a/src/builders/playwright/index.spec.ts b/src/builders/playwright/index.spec.ts index 38bde0a..fbafcd6 100644 --- a/src/builders/playwright/index.spec.ts +++ b/src/builders/playwright/index.spec.ts @@ -30,4 +30,20 @@ describe('Playwright builder', () => { expect.anything(), ); }); + + it('should accept --ui option', async () => { + const run = await architect.scheduleBuilder( + 'playwright-ng-schematics:playwright', + { ui: true }, + ); + + await run.result; + await run.stop(); + + expect(spawnSync).toHaveBeenCalledWith( + 'npx playwright test', + ['--ui'], + expect.anything(), + ); + }); }); diff --git a/src/builders/playwright/index.ts b/src/builders/playwright/index.ts index 4764c00..d7aae31 100644 --- a/src/builders/playwright/index.ts +++ b/src/builders/playwright/index.ts @@ -4,9 +4,34 @@ import { type BuilderOutput, createBuilder, } from '@angular-devkit/architect'; +import type { JsonObject } from '@angular-devkit/core'; -function runE2E(_options: undefined, _context: BuilderContext): BuilderOutput { - spawnSync('npx playwright test', [], { +interface Options extends JsonObject { + debug: boolean; + trace: string; + 'update-snapshots': boolean; + ui: boolean; +} + +function buildArgs(options: Options) { + const args = []; + if (options.debug) { + args.push('--debug'); + } + if (options.trace) { + args.push('--trace', options.trace); + } + if (options['update-snapshots']) { + args.push('--u'); + } + if (options.ui) { + args.push('--ui'); + } + return args; +} + +function runE2E(options: Options, _context: BuilderContext): BuilderOutput { + spawnSync('npx playwright test', buildArgs(options), { cwd: process.cwd(), stdio: 'inherit', shell: true, diff --git a/src/builders/playwright/schema.json b/src/builders/playwright/schema.json index 29f4377..674932b 100644 --- a/src/builders/playwright/schema.json +++ b/src/builders/playwright/schema.json @@ -1,4 +1,31 @@ { + "$schema": "http://json-schema.org/draft-07/schema", "title": "Playwright", - "description": "Playwright builder options" + "description": "Playwright builder options", + "type": "object", + "properties": { + "debug": { + "description": "Run tests with Playwright Inspector", + "type": "boolean" + }, + "trace": { + "description": "Force tracing mode", + "enum": [ + "on", + "off", + "on-first-retry", + "on-all-retries", + "retain-on-failure", + "retain-on-first-failure" + ] + }, + "u": { + "description": "Update snapshots with actual results", + "type": "boolean" + }, + "ui": { + "description": "Run tests in interactive UI mode", + "type": "boolean" + } + } }