Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(cli): make install-deps --dry-run report missing packages (#40615)

Pavel Feldmanb25fbe4da0be
diff --git a/docs/src/test-cli-js.md b/docs/src/test-cli-js.md
index abf499a3b6..fabc0f62fe 100644
--- a/docs/src/test-cli-js.md
+++ b/docs/src/test-cli-js.md
@@ -223,7 +223,7 @@ npx playwright install --with-deps
| Option | Description |
| :--- | :--- |
-| `--dry-run` | Don't perform installation, just print information |
+| `--dry-run` | Don't modify the system. On Linux, simulates the install via apt-get and exits with a non-zero code if any required packages are missing — useful for non-interactive verification scripts. On Windows, prints the install command. |
## Generation & Debugging Tools
diff --git a/packages/playwright-core/src/cli/program.ts b/packages/playwright-core/src/cli/program.ts
index a55f2f12e4..afb51d56be 100644
--- a/packages/playwright-core/src/cli/program.ts
+++ b/packages/playwright-core/src/cli/program.ts
@@ -107,7 +107,7 @@ export function decorateProgram(program: Command) {
program
.command('install-deps [browser...]')
.description('install dependencies necessary to run browsers (will ask for sudo permissions)')
- .option('--dry-run', 'Do not execute installation commands, only print them')
+ .option('--dry-run', 'Do not modify the system. On Linux, simulate the install via apt-get and exit with a non-zero code if any required packages are missing; on Windows, print the install command.')
.action(async function(args: string[], options: { dryRun?: boolean }) {
try {
await installDeps(args, options);
@@ -121,7 +121,10 @@ export function decorateProgram(program: Command) {
Install dependencies for default browsers.
- $ install-deps chrome firefox
- Install dependencies for specific browsers, supports chromium, firefox, webkit, chromium-headless-shell.`);
+ Install dependencies for specific browsers, supports chromium, firefox, webkit, chromium-headless-shell.
+
+ - $ install-deps --dry-run
+ Report which required system dependencies are missing without modifying the system. Exits non-zero if any are missing. Useful for non-interactive verification scripts.`);
const browsers = [
{ alias: 'cr', name: 'Chromium', type: 'chromium' },
diff --git a/packages/playwright-core/src/server/registry/dependencies.ts b/packages/playwright-core/src/server/registry/dependencies.ts
index 48e96f58c9..8d0b47911a 100644
--- a/packages/playwright-core/src/server/registry/dependencies.ts
+++ b/packages/playwright-core/src/server/registry/dependencies.ts
@@ -103,18 +103,17 @@ export async function installDependenciesLinux(targets: Set<DependencyGroup>, dr
libraries.push(...info[target]);
}
const uniqueLibraries = Array.from(new Set(libraries));
- if (!dryRun)
- console.log(`Installing dependencies...`); // eslint-disable-line no-console
+ if (dryRun) {
+ await reportMissingDependenciesLinux(uniqueLibraries);
+ return;
+ }
+ console.log(`Installing dependencies...`); // eslint-disable-line no-console
const commands: string[] = [];
commands.push('apt-get update');
commands.push(['apt-get', 'install', '-y', '--no-install-recommends',
...uniqueLibraries,
].join(' '));
const { command, args, elevatedPermissions } = await transformCommandsForRoot(commands);
- if (dryRun) {
- console.log(`${command} ${quoteProcessArgs(args).join(' ')}`); // eslint-disable-line no-console
- return;
- }
if (elevatedPermissions)
console.log('Switching to root user to install dependencies...'); // eslint-disable-line no-console
const child = childProcess.spawn(command, args, { stdio: 'inherit' });
@@ -124,6 +123,30 @@ export async function installDependenciesLinux(targets: Set<DependencyGroup>, dr
});
}
+async function reportMissingDependenciesLinux(packages: string[]) {
+ // `apt-get install -s` simulates the install: it does not need root and does not
+ // modify the system. Stdout includes one `Inst <package> ...` line per package
+ // that would be installed (i.e. that is currently missing).
+ const { code, stdout, stderr, error } = await spawnAsync('apt-get', ['install', '-s', '--no-install-recommends', ...packages], {});
+ if (error)
+ throw new Error(`Failed to run 'apt-get install -s' to simulate dependency install: ${error.message}`);
+ if (code !== 0)
+ throw new Error(`'apt-get install -s' exited with code ${code}:\n${stderr || stdout}`);
+ const missingPackages: string[] = [];
+ for (const line of stdout.split('\n')) {
+ const match = /^Inst (\S+) /.exec(line);
+ if (match)
+ missingPackages.push(match[1]);
+ }
+ if (!missingPackages.length) {
+ console.log('All system dependencies are installed.'); // eslint-disable-line no-console
+ return;
+ }
+ // eslint-disable-next-line no-console
+ console.log(`Missing system dependencies (${missingPackages.length}):\n${missingPackages.sort().map(p => ` ${p}`).join('\n')}`);
+ process.exitCode = 1;
+}
+
export async function validateDependenciesWindows(sdkLanguage: string, windowsExeAndDllDirectories: string[]) {
const directoryPaths = windowsExeAndDllDirectories;
const lddPaths: string[] = [];