Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov committed Sep 6, 2022
1 parent 2e02eed commit d75700c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
21 changes: 0 additions & 21 deletions packages/playwright-core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions packages/playwright-core/src/cli/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -207,7 +207,7 @@ async function wsEndpointInternal(): Promise<string|undefined> {
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) {
Expand Down Expand Up @@ -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) {
Expand Down
25 changes: 23 additions & 2 deletions packages/playwright-test/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d75700c

Please sign in to comment.