feat(cli): make run-driver work (#4836)
This commit is contained in:
parent
293a7bdd4c
commit
068d8612a7
|
|
@ -22,7 +22,6 @@ import * as path from 'path';
|
|||
import * as program from 'commander';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import { installBrowsersWithProgressBar } from '../install/installer';
|
||||
import * as consoleApiSource from '../generated/consoleApiSource';
|
||||
import { OutputMultiplexer, TerminalOutput, FileOutput } from './codegen/outputs';
|
||||
import { CodeGenerator, CodeGeneratorOutput } from './codegen/codeGenerator';
|
||||
|
|
@ -30,6 +29,7 @@ import { JavaScriptLanguageGenerator, LanguageGenerator } from './codegen/langua
|
|||
import { PythonLanguageGenerator } from './codegen/languages/python';
|
||||
import { CSharpLanguageGenerator } from './codegen/languages/csharp';
|
||||
import { RecorderController } from './codegen/recorderController';
|
||||
import { runServer, printApiJson, installBrowsers } from './driver';
|
||||
import type { Browser, BrowserContext, Page, BrowserType, BrowserContextOptions, LaunchOptions } from '../..';
|
||||
import * as playwright from '../..';
|
||||
|
||||
|
|
@ -130,19 +130,18 @@ program
|
|||
.command('install')
|
||||
.description('Ensure browsers necessary for this version of Playwright are installed')
|
||||
.action(function() {
|
||||
let browsersJsonDir = path.dirname(process.execPath);
|
||||
if (!fs.existsSync(path.join(browsersJsonDir, 'browsers.json'))) {
|
||||
browsersJsonDir = path.join(__dirname, '..', '..');
|
||||
if (!fs.existsSync(path.join(browsersJsonDir, 'browsers.json')))
|
||||
throw new Error('Failed to find browsers.json in ' + browsersJsonDir);
|
||||
}
|
||||
installBrowsersWithProgressBar(browsersJsonDir).catch((e: any) => {
|
||||
installBrowsers().catch((e: any) => {
|
||||
console.log(`Failed to install browsers\n${e}`);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
if (process.argv[2] === 'run-driver')
|
||||
runServer();
|
||||
else if (process.argv[2] === 'print-api-json')
|
||||
printApiJson();
|
||||
else
|
||||
program.parse(process.argv);
|
||||
|
||||
|
||||
type Options = {
|
||||
|
|
|
|||
|
|
@ -14,33 +14,26 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as util from 'util';
|
||||
import { installDebugController } from './debug/debugController';
|
||||
import { DispatcherConnection } from './dispatchers/dispatcher';
|
||||
import { PlaywrightDispatcher } from './dispatchers/playwrightDispatcher';
|
||||
import { installBrowsersWithProgressBar } from './install/installer';
|
||||
import { Transport } from './protocol/transport';
|
||||
import { Playwright } from './server/playwright';
|
||||
import { gracefullyCloseAll } from './server/processLauncher';
|
||||
import { installHarTracer } from './trace/harTracer';
|
||||
import { installTracer } from './trace/tracer';
|
||||
import * as path from 'path';
|
||||
import { installDebugController } from '../debug/debugController';
|
||||
import { DispatcherConnection } from '../dispatchers/dispatcher';
|
||||
import { PlaywrightDispatcher } from '../dispatchers/playwrightDispatcher';
|
||||
import { installBrowsersWithProgressBar } from '../install/installer';
|
||||
import { Transport } from '../protocol/transport';
|
||||
import { Playwright } from '../server/playwright';
|
||||
import { gracefullyCloseAll } from '../server/processLauncher';
|
||||
import { installHarTracer } from '../trace/harTracer';
|
||||
import { installTracer } from '../trace/tracer';
|
||||
|
||||
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
|
||||
export async function copyPrintDeps(destination: string) {
|
||||
const content = await readFileAsync(require.resolve('../bin/PrintDeps.exe'));
|
||||
await writeFileAsync(destination, content);
|
||||
export function printApiJson() {
|
||||
console.log(JSON.stringify(require('../../api.json')));
|
||||
}
|
||||
|
||||
export async function installWithProgressBar(location: string) {
|
||||
await installBrowsersWithProgressBar(location);
|
||||
}
|
||||
|
||||
export async function apiJson(): Promise<string> {
|
||||
return (await readFileAsync(require.resolve('../docs/api.json'))).toString();
|
||||
export function printProtocol() {
|
||||
console.log(fs.readFileSync(path.join(__dirname, '..', '..', 'protocol.yml'), 'utf8'));
|
||||
}
|
||||
|
||||
export function runServer() {
|
||||
|
|
@ -62,9 +55,16 @@ export function runServer() {
|
|||
process.exit(0);
|
||||
};
|
||||
|
||||
const playwright = new Playwright(__dirname, require('../browsers.json')['browsers']);
|
||||
const playwright = new Playwright(__dirname, require('../../browsers.json')['browsers']);
|
||||
new PlaywrightDispatcher(dispatcherConnection.rootDispatcher(), playwright);
|
||||
}
|
||||
|
||||
if (process.argv[2] === 'serve')
|
||||
runServer();
|
||||
export async function installBrowsers() {
|
||||
let browsersJsonDir = path.dirname(process.execPath);
|
||||
if (!fs.existsSync(path.join(browsersJsonDir, 'browsers.json'))) {
|
||||
browsersJsonDir = path.join(__dirname, '..', '..');
|
||||
if (!fs.existsSync(path.join(browsersJsonDir, 'browsers.json')))
|
||||
throw new Error('Failed to find browsers.json in ' + browsersJsonDir);
|
||||
}
|
||||
await installBrowsersWithProgressBar(browsersJsonDir);
|
||||
}
|
||||
|
|
@ -108,7 +108,7 @@ fixtures.playwright.override(async ({ browserName, testWorkerIndex, platform, mo
|
|||
if (mode === 'driver') {
|
||||
require('../lib/utils/utils').setUnderTest();
|
||||
const connection = new Connection();
|
||||
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'driver.js'), ['serve'], {
|
||||
const spawnedProcess = childProcess.fork(path.join(__dirname, '..', 'lib', 'cli', 'cli.js'), ['run-driver'], {
|
||||
stdio: 'pipe',
|
||||
detached: true,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ DEPS['src/server/android/'] = [...DEPS['src/server/'], 'src/server/chromium/', '
|
|||
DEPS['src/server/electron/'] = [...DEPS['src/server/'], 'src/server/chromium/'];
|
||||
|
||||
DEPS['src/server/playwright.ts'] = [...DEPS['src/server/'], 'src/server/chromium/', 'src/server/webkit/', 'src/server/firefox/', 'src/server/android/', 'src/server/electron/'];
|
||||
DEPS['src/driver.ts'] = DEPS['src/inprocess.ts'] = DEPS['src/browserServerImpl.ts'] = ['src/**'];
|
||||
DEPS['src/cli/driver.ts'] = DEPS['src/inprocess.ts'] = DEPS['src/browserServerImpl.ts'] = ['src/**'];
|
||||
|
||||
// Tracing is a client/server plugin, nothing should depend on it.
|
||||
DEPS['src/trace/'] = ['src/utils/', 'src/client/**', 'src/server/**'];
|
||||
|
|
|
|||
Loading…
Reference in a new issue