Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: split cli processing into cli endpoint and program (#29131)
Pavel Feldmancec2ff1772a0
diff --git a/packages/playwright-chromium/cli.js b/packages/playwright-chromium/cli.jsindex bd995de114..86adb86a84 100755--- a/packages/playwright-chromium/cli.js+++ b/packages/playwright-chromium/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright-core/lib/cli/cli');++const { program } = require('playwright-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-core/cli.js b/packages/playwright-core/cli.jsindex bd995de114..fb309ead0a 100755--- a/packages/playwright-core/cli.js+++ b/packages/playwright-core/cli.js@@ -14,4 +14,5 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright-core/lib/cli/cli');+const { program } = require('./lib/cli/programWithTestStub');+program.parse(process.argv);diff --git a/packages/playwright-core/package.json b/packages/playwright-core/package.jsonindex eb8667a8b4..c846a750e7 100644--- a/packages/playwright-core/package.json+++ b/packages/playwright-core/package.json@@ -27,7 +27,6 @@"./lib/image_tools/compare": "./lib/image_tools/compare.js","./lib/image_tools/imageChannel": "./lib/image_tools/imageChannel.js","./lib/image_tools/colorUtils": "./lib/image_tools/colorUtils.js",- "./lib/cli/cli": "./lib/cli/cli.js","./lib/cli/program": "./lib/cli/program.js","./lib/server/registry/index": "./lib/server/registry/index.js","./lib/remote/playwrightServer": "./lib/remote/playwrightServer.js",diff --git a/packages/playwright-core/src/cli/program.ts b/packages/playwright-core/src/cli/program.tsindex 6e67df3f38..8a00626d19 100644--- a/packages/playwright-core/src/cli/program.ts+++ b/packages/playwright-core/src/cli/program.ts@@ -21,6 +21,7 @@ import os from 'os';import path from 'path';import type { Command } from '../utilsBundle';import { program } from '../utilsBundle';+export { program } from '../utilsBundle';import { runDriver, runServer, printApiJson, launchBrowserServer } from './driver';import type { OpenTraceViewerOptions } from '../server/trace/viewer/traceViewer';import { openTraceInBrowser, openTraceViewerApp } from '../server/trace/viewer/traceViewer';@@ -690,5 +691,3 @@ function buildBasePlaywrightCLICommand(cliTargetLang: string | undefined): strin}}}--export default program;diff --git a/packages/playwright-core/src/cli/cli.ts b/packages/playwright-core/src/cli/programWithTestStub.tsold mode 100755new mode 100644similarity index 96%rename from packages/playwright-core/src/cli/cli.tsrename to packages/playwright-core/src/cli/programWithTestStub.tsindex 8681efe73a..1c11c14ec2--- a/packages/playwright-core/src/cli/cli.ts+++ b/packages/playwright-core/src/cli/programWithTestStub.ts@@ -1,5 +1,3 @@-#!/usr/bin/env node-/*** Copyright (c) Microsoft Corporation.*@@ -19,7 +17,8 @@/* eslint-disable no-console */import { getPackageManager, gracefullyProcessExitDoNotHang } from '../utils';-import program from './program';+import { program } from './program';+export { program } from './program';function printPlaywrightTestError(command: string) {const packages: string[] = [];@@ -66,5 +65,3 @@ function addExternalPlaywrightTestCommands() {if (!process.env.PW_LANG_NAME)addExternalPlaywrightTestCommands();--program.parse(process.argv);diff --git a/packages/playwright-core/src/outofprocess.ts b/packages/playwright-core/src/outofprocess.tsindex 537f37c28d..81deaead67 100644--- a/packages/playwright-core/src/outofprocess.ts+++ b/packages/playwright-core/src/outofprocess.ts@@ -34,7 +34,7 @@ class PlaywrightClient {private _closePromise = new ManualPromise<void>();constructor(env: any) {- this._driverProcess = childProcess.fork(path.join(__dirname, 'cli', 'cli.js'), ['run-driver'], {+ this._driverProcess = childProcess.fork(path.join(__dirname, '..', 'cli.js'), ['run-driver'], {stdio: 'pipe',detached: true,env: {diff --git a/packages/playwright-ct-core/cli.js b/packages/playwright-ct-core/cli.jsindex 2d0ff42281..5db59b62cd 100755--- a/packages/playwright-ct-core/cli.js+++ b/packages/playwright-ct-core/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright/lib/cli');++const { program } = require('./lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-core/package.json b/packages/playwright-ct-core/package.jsonindex 5113fde082..08076282d1 100644--- a/packages/playwright-ct-core/package.json+++ b/packages/playwright-ct-core/package.json@@ -19,8 +19,8 @@"types": "./index.d.ts","default": "./index.js"},- "./cli": "./cli.js","./lib/mount": "./lib/mount.js",+ "./lib/program": "./lib/program.js","./plugin": "./plugin.js","./types/component": {"types": "./types/component.d.ts"diff --git a/packages/playwright-ct-core/src/program.ts b/packages/playwright-ct-core/src/program.tsnew file mode 100644index 0000000000..3014578d69--- /dev/null+++ b/packages/playwright-ct-core/src/program.ts@@ -0,0 +1,17 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export { program } from 'playwright/lib/program';diff --git a/packages/playwright-ct-react/cli.js b/packages/playwright-ct-react/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-react/cli.js+++ b/packages/playwright-ct-react/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-react17/cli.js b/packages/playwright-ct-react17/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-react17/cli.js+++ b/packages/playwright-ct-react17/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-solid/cli.js b/packages/playwright-ct-solid/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-solid/cli.js+++ b/packages/playwright-ct-solid/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-svelte/cli.js b/packages/playwright-ct-svelte/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-svelte/cli.js+++ b/packages/playwright-ct-svelte/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-vue/cli.js b/packages/playwright-ct-vue/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-vue/cli.js+++ b/packages/playwright-ct-vue/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-ct-vue2/cli.js b/packages/playwright-ct-vue2/cli.jsindex 14f0c7df88..db414c5904 100755--- a/packages/playwright-ct-vue2/cli.js+++ b/packages/playwright-ct-vue2/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('@playwright/experimental-ct-core/cli');++const { program } = require('@playwright/experimental-ct-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-firefox/cli.js b/packages/playwright-firefox/cli.jsindex bd995de114..86adb86a84 100755--- a/packages/playwright-firefox/cli.js+++ b/packages/playwright-firefox/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright-core/lib/cli/cli');++const { program } = require('playwright-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-test/cli.js b/packages/playwright-test/cli.jsindex 9d6dee9693..e42facb076 100755--- a/packages/playwright-test/cli.js+++ b/packages/playwright-test/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright/cli');++const { program } = require('playwright/lib/program');+program.parse(process.argv);diff --git a/packages/playwright-webkit/cli.js b/packages/playwright-webkit/cli.jsindex bd995de114..86adb86a84 100755--- a/packages/playwright-webkit/cli.js+++ b/packages/playwright-webkit/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('playwright-core/lib/cli/cli');++const { program } = require('playwright-core/lib/program');+program.parse(process.argv);diff --git a/packages/playwright/cli.js b/packages/playwright/cli.jsindex d4eb087af8..5db59b62cd 100755--- a/packages/playwright/cli.js+++ b/packages/playwright/cli.js@@ -14,4 +14,6 @@* See the License for the specific language governing permissions and* limitations under the License.*/-module.exports = require('./lib/cli');++const { program } = require('./lib/program');+program.parse(process.argv);diff --git a/packages/playwright/package.json b/packages/playwright/package.jsonindex 7c3e9cae7d..d48364ec90 100644--- a/packages/playwright/package.json+++ b/packages/playwright/package.json@@ -18,9 +18,8 @@"require": "./index.js","default": "./index.js"},- "./cli": "./cli.js","./package.json": "./package.json",- "./lib/cli": "./lib/cli.js",+ "./lib/program": "./lib/program.js","./lib/transform/babelBundle": "./lib/transform/babelBundle.js","./lib/transform/compilationCache": "./lib/transform/compilationCache.js","./lib/transform/esmLoader": "./lib/transform/esmLoader.js",diff --git a/packages/playwright/src/DEPS.list b/packages/playwright/src/DEPS.listindex c7a905a82b..200d75de1a 100644--- a/packages/playwright/src/DEPS.list+++ b/packages/playwright/src/DEPS.list@@ -3,7 +3,7 @@ common/./utils.ts./utilsBundle.ts-[cli.ts]+[program.ts]**[index.ts]diff --git a/packages/playwright/src/cli.ts b/packages/playwright/src/program.tssimilarity index 98%rename from packages/playwright/src/cli.tsrename to packages/playwright/src/program.tsindex 34a0b2372c..98bf8f1d12 100644--- a/packages/playwright/src/cli.ts+++ b/packages/playwright/src/program.ts@@ -30,7 +30,8 @@ import type { FullResult, TestError } from '../types/testReporter';import type { TraceMode } from '../types/test';import { builtInReporters, defaultReporter, defaultTimeout } from './common/config';import type { FullConfigInternal } from './common/config';-import program from 'playwright-core/lib/cli/program';+import { program } from 'playwright-core/lib/cli/program';+export { program } from 'playwright-core/lib/cli/program';import type { ReporterDescription } from '../types/test';import { prepareErrorStack } from './reporters/base';import { registerESMLoader } from './common/esmLoaderHost';@@ -289,7 +290,7 @@ function restartWithExperimentalTsEsm(configFile: string | null): boolean {return false;// Node.js < 20if (!require('node:module').register) {- const innerProcess = (require('child_process') as typeof import('child_process')).fork(require.resolve('./cli'), process.argv.slice(2), {+ const innerProcess = (require('child_process') as typeof import('child_process')).fork(require.resolve('../cli'), process.argv.slice(2), {env: {...process.env,PW_TS_ESM_LEGACY_LOADER_ON: '1',@@ -346,5 +347,3 @@ addTestCommand(program);addShowReportCommand(program);addListFilesCommand(program);addMergeReportsCommand(program);--program.parse(process.argv);diff --git a/tests/config/remoteServer.ts b/tests/config/remoteServer.tsindex 05ddae2179..04305f31a4 100644--- a/tests/config/remoteServer.ts+++ b/tests/config/remoteServer.ts@@ -28,7 +28,7 @@ export class RunServer implements PlaywrightServer {_wsEndpoint!: string;async start(childProcess: CommonFixtures['childProcess'], mode?: 'extension' | 'default', env?: NodeJS.ProcessEnv) {- const command = ['node', path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'lib', 'cli', 'cli.js'), 'run-server'];+ const command = ['node', path.join(__dirname, '..', '..', 'packages', 'playwright-core', 'cli.js'), 'run-server'];if (mode === 'extension')command.push('--mode=extension');this._process = childProcess({diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.tsindex 2730a5df03..8485c9f219 100644--- a/tests/library/inspector/inspectorTest.ts+++ b/tests/library/inspector/inspectorTest.ts@@ -202,7 +202,7 @@ class CLIMock {constructor(childProcess: CommonFixtures['childProcess'], browserName: string, channel: string | undefined, headless: boolean | undefined, args: string[], executablePath: string | undefined, autoExitWhen: string | undefined) {const nodeArgs = ['node',- path.join(__dirname, '..', '..', '..', 'packages', 'playwright-core', 'lib', 'cli', 'cli.js'),+ path.join(__dirname, '..', '..', '..', 'packages', 'playwright-core', 'cli.js'),'codegen',...args,`--browser=${browserName}`,diff --git a/utils/build/run-driver-posix.sh b/utils/build/run-driver-posix.shindex d00a15ba42..af4ed059c5 100755--- a/utils/build/run-driver-posix.sh+++ b/utils/build/run-driver-posix.sh@@ -3,4 +3,4 @@ SCRIPT_PATH="$(cd "$(dirname "$0")" ; pwd -P)"if [ -z "$PLAYWRIGHT_NODEJS_PATH" ]; thenPLAYWRIGHT_NODEJS_PATH="$SCRIPT_PATH/node"fi-"$PLAYWRIGHT_NODEJS_PATH" "$SCRIPT_PATH/package/lib/cli/cli.js" "$@"+"$PLAYWRIGHT_NODEJS_PATH" "$SCRIPT_PATH/package/cli.js" "$@"