diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts index 5f5a0d1a44ef23..8c83ab95eabeaf 100755 --- a/packages/playwright-core/src/cli/cli.ts +++ b/packages/playwright-core/src/cli/cli.ts @@ -345,6 +345,7 @@ if (!process.env.PW_LANG_NAME) { } require(playwrightTestPackagePath).addTestCommands(program); + require(playwrightTestPackagePath).addDockerTestCommand(dockerCommand); } else { { const command = program.command('test').allowUnknownOption(true); diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts index 1c1d767c3149c4..1f890138da8689 100644 --- a/packages/playwright-test/src/cli.ts +++ b/packages/playwright-test/src/cli.ts @@ -30,12 +30,16 @@ import { baseFullConfig, defaultTimeout, fileIsModule } from './loader'; import type { TraceMode } from './types'; export function addTestCommands(program: Command) { - addTestCommand(program); + addTestCommand(program, false /* isDocker */); addShowReportCommand(program); addListFilesCommand(program); } -function addTestCommand(program: Command) { +export function addDockerTestCommand(subCommand: Command) { + addTestCommand(subCommand, true /* isDocker */); +} + +function addTestCommand(program: Command, isDocker: boolean) { const command = program.command('test [test-filter...]'); command.description('Run tests with Playwright Test'); command.option('--browser ', `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")`); @@ -53,7 +57,6 @@ function addTestCommand(program: Command) { command.option('--output ', `Folder for output artifacts (default: "test-results")`); command.option('--pass-with-no-tests', `Makes test run succeed even if no tests were found`); command.option('--quiet', `Suppress stdio`); - command.option('--docker', `Launch tests inside docker container`); command.option('--repeat-each ', `Run each test N times (default: 1)`); command.option('--reporter ', `Reporter to use, comma-separated, can be ${builtInReporters.map(name => `"${name}"`).join(', ')} (default: "${baseFullConfig.reporter[0]}")`); command.option('--retries ', `Maximum retry count for flaky tests, zero for no retries (default: no retries)`); @@ -65,6 +68,16 @@ function addTestCommand(program: Command) { command.option('-x', `Stop after the first failure`); command.action(async (args, opts) => { try { + if (isDocker) { + const wsEndpoint = await docker.wsEndpoint(); + if (!wsEndpoint) + throw new Error(`Playwright docker container is not running; run "npx playwright docker start" first`); + process.env.PW_TEST_CONNECT_WS_ENDPOINT = await docker.wsEndpoint(); + process.env.PW_TEST_CONNECT_HEADERS = JSON.stringify({ + 'x-playwright-proxy': '*', + }); + process.env.PW_TEST_IS_DOCKER = '1'; + } await runTests(args, opts); } catch (e) { console.error(e); @@ -76,10 +89,10 @@ Arguments [test-filter...]: Pass arguments to filter test files. Each argument is treated as a regular expression. Examples: - $ npx playwright test my.spec.ts - $ npx playwright test some.spec.ts:42 - $ npx playwright test --headed - $ npx playwright test --browser=webkit`); + $ npx playwright${isDocker ? ' docker ' : ' '}test my.spec.ts + $ npx playwright${isDocker ? ' docker ' : ' '}test some.spec.ts:42 + $ npx playwright${isDocker ? ' docker ' : ' '}test --headed + $ npx playwright${isDocker ? ' docker ' : ' '}test --browser=webkit`); } function addListFilesCommand(program: Command) { @@ -127,17 +140,6 @@ async function runTests(args: string[], opts: { [key: string]: any }) { }); } - if (opts.docker) { - const wsEndpoint = await docker.wsEndpoint(); - if (!wsEndpoint) - throw new Error(`Playwright docker container is not running; run "npx playwright docker start" first`); - process.env.PW_TEST_CONNECT_WS_ENDPOINT = await docker.wsEndpoint(); - process.env.PW_TEST_CONNECT_HEADERS = JSON.stringify({ - 'x-playwright-proxy': '*', - }); - process.env.PW_TEST_IS_DOCKER = '1'; - } - if (opts.headed || opts.debug) overrides.use = { headless: false }; if (opts.debug) {