feat(cli): launch-server command (#5713)
This commit is contained in:
parent
5c46a61dba
commit
26b7db964c
|
|
@ -22,7 +22,7 @@ import path from 'path';
|
||||||
import program from 'commander';
|
import program from 'commander';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { runServer, printApiJson, installBrowsers } from './driver';
|
import { runServer, printApiJson, launchBrowserServer, installBrowsers } from './driver';
|
||||||
import { showTraceViewer } from '../server/trace/viewer/traceViewer';
|
import { showTraceViewer } from '../server/trace/viewer/traceViewer';
|
||||||
import * as playwright from '../..';
|
import * as playwright from '../..';
|
||||||
import { BrowserContext } from '../client/browserContext';
|
import { BrowserContext } from '../client/browserContext';
|
||||||
|
|
@ -160,6 +160,8 @@ if (process.argv[2] === 'run-driver')
|
||||||
runServer();
|
runServer();
|
||||||
else if (process.argv[2] === 'print-api-json')
|
else if (process.argv[2] === 'print-api-json')
|
||||||
printApiJson();
|
printApiJson();
|
||||||
|
else if (process.argv[2] === 'launch-server')
|
||||||
|
launchBrowserServer(process.argv[3], process.argv[4]);
|
||||||
else
|
else
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import * as playwright from '../..';
|
||||||
|
import { BrowserType } from '../client/browserType';
|
||||||
|
import { LaunchServerOptions } from '../client/types';
|
||||||
import { DispatcherConnection } from '../dispatchers/dispatcher';
|
import { DispatcherConnection } from '../dispatchers/dispatcher';
|
||||||
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
|
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
|
||||||
import { installBrowsersWithProgressBar } from '../install/installer';
|
import { installBrowsersWithProgressBar } from '../install/installer';
|
||||||
|
|
@ -53,6 +56,15 @@ export function runServer() {
|
||||||
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
|
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function launchBrowserServer(browserName: string, configFile?: string) {
|
||||||
|
let options: LaunchServerOptions = {};
|
||||||
|
if (configFile)
|
||||||
|
options = JSON.parse(fs.readFileSync(configFile).toString());
|
||||||
|
const browserType = (playwright as any)[browserName] as BrowserType;
|
||||||
|
const server = await browserType.launchServer(options);
|
||||||
|
console.log(server.wsEndpoint());
|
||||||
|
}
|
||||||
|
|
||||||
export async function installBrowsers(browserNames?: BrowserName[]) {
|
export async function installBrowsers(browserNames?: BrowserName[]) {
|
||||||
await installBrowsersWithProgressBar(browserNames);
|
await installBrowsersWithProgressBar(browserNames);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue