chore: support both test --ui and ui clis (#21537)

This commit is contained in:
Pavel Feldman 2023-03-09 13:03:01 -08:00 committed by GitHub
parent c30d88a63a
commit e7b21425f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View File

@ -30,7 +30,7 @@ import type { FullResult } from '../reporter';
export function addTestCommands(program: Command) {
addTestCommand(program);
addOpenCommand(program);
addUICommand(program);
addShowReportCommand(program);
addListFilesCommand(program);
}
@ -59,9 +59,9 @@ Examples:
$ npx playwright test --project=webkit`);
}
function addOpenCommand(program: Command) {
const command = program.command('gui [test-filter...]');
command.description('open Playwright Test UI');
function addUICommand(program: Command) {
const command = program.command('ui [test-filter...]');
command.description('open Playwright Test interactive UI');
sharedOptions.forEach(([name, description]) => command.option(name, description));
command.action(async (args, opts) => {
try {
@ -77,10 +77,10 @@ Arguments [test-filter...]:
Pass arguments to filter test files. Each argument is treated as a regular expression. Matching is performed against the absolute file paths.
Examples:
$ npx playwright gui my.spec.ts
$ npx playwright gui some.spec.ts:42
$ npx playwright gui --headed
$ npx playwright gui --project=webkit`);
$ npx playwright ui my.spec.ts
$ npx playwright ui some.spec.ts:42
$ npx playwright ui --headed
$ npx playwright ui --project=webkit`);
}
function addListFilesCommand(program: Command) {
@ -132,13 +132,13 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
if (opts.headed || opts.debug)
overrides.use = { headless: false };
if (opts.debug) {
if (!opts.ui && opts.debug) {
overrides.maxFailures = 1;
overrides.timeout = 0;
overrides.workers = 1;
process.env.PWDEBUG = '1';
}
if (opts.trace) {
if (!opts.ui && opts.trace) {
if (!kTraceModes.includes(opts.trace))
throw new Error(`Unsupported trace mode "${opts.trace}", must be one of ${kTraceModes.map(mode => `"${mode}"`).join(', ')}`);
overrides.use = overrides.use || {};
@ -288,5 +288,6 @@ const testOnlyOptions: [string, string][] = [
['--retries <retries>', `Maximum retry count for flaky tests, zero for no retries (default: no retries)`],
['--shard <shard>', `Shard tests and execute only the selected shard, specify in the form "current/all", 1-based, for example "3/5"`],
['--trace <mode>', `Force tracing mode, can be ${kTraceModes.map(mode => `"${mode}"`).join(', ')}`],
['--ui', `Run tests in interactive UI mode`],
['-u, --update-snapshots', `Update snapshots with actual results (default: only create missing snapshots)`],
];

View File

@ -40,7 +40,14 @@ class UIMode {
constructor(config: FullConfigInternal) {
this._config = config;
config._internal.configCLIOverrides.forbidOnly = false;
config._internal.configCLIOverrides.globalTimeout = 0;
config._internal.configCLIOverrides.repeatEach = 0;
config._internal.configCLIOverrides.shard = undefined;
config._internal.configCLIOverrides.updateSnapshots = undefined;
config._internal.listOnly = false;
config._internal.passWithNoTests = true;
for (const p of config.projects)
p.retries = 0;
config._internal.configCLIOverrides.use = config._internal.configCLIOverrides.use || {};