When running Playwright tests in a containerized environment, it is helpful to build a custom image with native dependencies preinstalled. It is possible to do this by manually examining the list of dependencies in the nativeDeps.ts file:
|
'ubuntu20.04': { |
|
tools: [ |
|
'xvfb', |
|
'fonts-noto-color-emoji', |
|
'ttf-unifont', |
|
'libfontconfig', |
|
'libfreetype6', |
|
'xfonts-cyrillic', |
|
'xfonts-scalable', |
|
'fonts-liberation', |
|
'fonts-ipafont-gothic', |
|
'fonts-wqy-zenhei', |
|
'fonts-tlwg-loma-otf', |
|
'ttf-ubuntu-font-family', |
|
], |
However, it would be convenient if there were a way to list all the dependencies that playwright would install, without actually running the install command. It looks like we can do this by separating the dependency list generation and installation commands, for example, create a function that returns uniqueLibraries and a separate function that accepts that as input, then spawns apt-get:
|
export async function installDependenciesLinux(targets: Set<DependencyGroup>) { |
|
const libraries: string[] = []; |
|
for (const target of targets) { |
|
const info = deps[utils.hostPlatform]; |
|
if (!info) { |
|
console.warn('Cannot install dependencies for this linux distribution!'); // eslint-disable-line no-console |
|
return; |
|
} |
|
libraries.push(...info[target]); |
|
} |
|
const uniqueLibraries = Array.from(new Set(libraries)); |
|
console.log('Installing Ubuntu 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] = await buildAptProcessArgs(commands); |
|
const child = childProcess.spawn(command, args, { stdio: 'inherit' }); |
|
await new Promise((resolve, reject) => { |
|
child.on('exit', resolve); |
|
child.on('error', reject); |
|
}); |
|
} |
I'd be happy to create a pull request if this is a feature you'd consider! I'd propose something like npx playwright install-deps --dry-run to return the package list for the current system
When running Playwright tests in a containerized environment, it is helpful to build a custom image with native dependencies preinstalled. It is possible to do this by manually examining the list of dependencies in the nativeDeps.ts file:
playwright/packages/playwright-core/src/utils/nativeDeps.ts
Lines 228 to 242 in d34f997
However, it would be convenient if there were a way to list all the dependencies that playwright would install, without actually running the install command. It looks like we can do this by separating the dependency list generation and installation commands, for example, create a function that returns uniqueLibraries and a separate function that accepts that as input, then spawns apt-get:
playwright/packages/playwright-core/src/utils/dependencies.ts
Lines 49 to 72 in d34f997
I'd be happy to create a pull request if this is a feature you'd consider! I'd propose something like
npx playwright install-deps --dry-runto return the package list for the current system