From d75700c3bea3d735acf615d61d06b27a295d3318 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 6 Sep 2022 00:07:22 -0400 Subject: [PATCH] refactoring --- packages/playwright-core/src/cli/cli.ts | 21 ------------------ packages/playwright-core/src/cli/docker.ts | 10 ++++----- packages/playwright-test/src/cli.ts | 25 ++++++++++++++++++++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/cli.ts index 8c83ab95eabeaf..4e2660786bab29 100755 --- a/packages/playwright-core/src/cli/cli.ts +++ b/packages/playwright-core/src/cli/cli.ts @@ -264,26 +264,6 @@ program runServer(options.port ? +options.port : undefined, options.path, options.maxClients ? +options.maxClients : Infinity, options.socksProxy, options.reuseBrowser).catch(logErrorAndExit); }); -const dockerCommand = program.command('docker', { hidden: true }); - -dockerCommand.command('start') - .description('Start VRT container') - .action(function(options) { - docker.startVRTService(); - }); - -dockerCommand.command('stop') - .description('Stop VRT container') - .action(function(options) { - docker.stopVRTService(); - }); - -dockerCommand.command('install') - .description('Install docker image for visual regression testing') - .action(function(options) { - docker.buildVRTDockerImage(); - }); - program .command('print-api-json', { hidden: true }) .action(function(options) { @@ -345,7 +325,6 @@ 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-core/src/cli/docker.ts b/packages/playwright-core/src/cli/docker.ts index 5ad8102fb0cedd..50ec3081d925eb 100644 --- a/packages/playwright-core/src/cli/docker.ts +++ b/packages/playwright-core/src/cli/docker.ts @@ -115,7 +115,7 @@ const CONTAINER_BUILD_SCRIPT = ` mkdir /root/.fluxbox && mv /ms-playwright-agent/configuration.txt /root/.fluxbox/menu `.split('\n').map(line => line.substring(2)).join('\n');; -export async function buildVRTDockerImage() { +export async function installImage() { await ensureDockerIsRunning(); const isDevelopmentMode = getPlaywrightVersion().includes('next'); let baseImageName = `mcr.microsoft.com/playwright:v${getPlaywrightVersion()}-${VRT_IMAGE_DISTRO}`; @@ -207,7 +207,7 @@ async function wsEndpointInternal(): Promise { return webSocketLine ? 'ws://' + webSocketLine.substring(LINE_PREFIX.length) : undefined; } -export async function startVRTService() { +export async function startContainer() { await ensureDockerIsRunning(); const pwImage = await findDockerImage(VRT_IMAGE_NAME); if (!pwImage) { @@ -250,11 +250,11 @@ export async function startVRTService() { console.log(`- VNC session: http://127.0.0.1:7900?path=${utils.createGuid()}&resize=scale`); console.log(`- WS endpoint: ${endpoint}`); console.log(``); - console.log(`You can now run tests with browsers from this container:`); - console.log(` npx playwright test --docker`); + console.log(`You can now run tests with browsers inside this container:`); + console.log(` npx playwright docker test`); } -export async function stopVRTService() { +export async function stopContainer() { await ensureDockerIsRunning(); const containerId = await findRunningDockerContainerId(); if (!containerId) { diff --git a/packages/playwright-test/src/cli.ts b/packages/playwright-test/src/cli.ts index ac839e29cff1db..face478712d9aa 100644 --- a/packages/playwright-test/src/cli.ts +++ b/packages/playwright-test/src/cli.ts @@ -33,10 +33,31 @@ export function addTestCommands(program: Command) { addTestCommand(program, false /* isDocker */); addShowReportCommand(program); addListFilesCommand(program); + addDockerCommand(program); } -export function addDockerTestCommand(subCommand: Command) { - addTestCommand(subCommand, true /* isDocker */); +function addDockerCommand(program: Command) { + const dockerCommand = program.command('docker', { hidden: true }); + + dockerCommand.command('install') + .description('Install docker image for visual regression testing') + .action(function(options) { + docker.installImage(); + }); + + dockerCommand.command('start') + .description('Start container') + .action(function(options) { + docker.startContainer(); + }); + + dockerCommand.command('stop') + .description('Stop container') + .action(function(options) { + docker.stopContainer(); + }); + + addTestCommand(dockerCommand, true /* isDocker */); } function addTestCommand(program: Command, isDocker: boolean) {