Skip to content

Commit

Permalink
feat: CLI options
Browse files Browse the repository at this point in the history
  • Loading branch information
jfgreffier committed Sep 18, 2024
1 parent 8a57904 commit 4c4ce49
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/builders/playwright/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
});
});
29 changes: 27 additions & 2 deletions src/builders/playwright/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 28 additions & 1 deletion src/builders/playwright/schema.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 4c4ce49

Please sign in to comment.