fix: host dependency validation (#6227)

This commit is contained in:
Max Schmitt 2021-04-20 18:54:53 +02:00 committed by GitHub
parent f9af4c3755
commit 9cd89ae052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 21 deletions

View File

@ -42,6 +42,8 @@ function copy_test_scripts {
cp "${SCRIPTS_PATH}/inspector-custom-executable.js" .
cp "${SCRIPTS_PATH}/sanity.js" .
cp "${SCRIPTS_PATH}/screencast.js" .
cp "${SCRIPTS_PATH}/validate-dependencies.js" .
cp "${SCRIPTS_PATH}/validate-dependencies-skip-executable-path.js" .
cp "${SCRIPTS_PATH}/esm.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
@ -64,6 +66,8 @@ function run_tests {
test_playwright_chromium_should_work
test_playwright_webkit_should_work
test_playwright_firefox_should_work
test_playwright_validate_dependencies
test_playwright_validate_dependencies_skip_executable_path
test_playwright_global_installation
test_playwright_global_installation_cross_package
test_playwright_electron_should_work
@ -359,6 +363,36 @@ function test_playwright_firefox_should_work {
echo "${FUNCNAME[0]} success"
}
function test_playwright_validate_dependencies {
initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_TGZ}
copy_test_scripts
OUTPUT="$(node validate-dependencies.js)"
if [[ "${OUTPUT}" != *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then
echo "ERROR: validateDependencies was not called"
exit 1
fi
echo "${FUNCNAME[0]} success"
}
function test_playwright_validate_dependencies_skip_executable_path {
initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_TGZ}
copy_test_scripts
OUTPUT="$(node validate-dependencies-skip-executable-path.js)"
if [[ "${OUTPUT}" == *"PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS"* ]]; then
echo "ERROR: validateDependencies was called"
exit 1
fi
echo "${FUNCNAME[0]} success"
}
function test_playwright_electron_should_work {
initialize_test "${FUNCNAME[0]}"

View File

@ -0,0 +1,10 @@
const playwright = require('playwright');
process.env.PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = 1;
(async () => {
const browser = await playwright.chromium.launch({
executablePath: playwright.chromium.executablePath()
});
await browser.close();
})();

View File

@ -0,0 +1,8 @@
const playwright = require('playwright');
process.env.PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = 1;
(async () => {
const browser = await playwright.chromium.launch();
await browser.close();
})();

View File

@ -74,7 +74,7 @@ async function validateCache(linksDir: string, browserNames: BrowserName[]) {
linkTarget = (await fsReadFileAsync(linkPath)).toString();
const linkRegistry = new Registry(linkTarget);
for (const browserName of allBrowserNames) {
if (!linkRegistry.shouldRetain(browserName))
if (!linkRegistry.isSupportedBrowser(browserName))
continue;
const usedBrowserPath = linkRegistry.browserDirectory(browserName);
const browserRevision = linkRegistry.revision(browserName);

View File

@ -178,10 +178,11 @@ export abstract class BrowserType extends SdkObject {
throw new Error(errorMessageLines.join('\n'));
}
if (!executable) {
// Only validate dependencies for bundled browsers.
// Only validate dependencies for downloadable browsers.
if (!executablePath && !options.channel)
await validateHostRequirements(this._registry, this._name);
}
else if (!executablePath && options.channel && this._registry.isSupportedBrowser(options.channel))
await validateHostRequirements(this._registry, options.channel as registry.BrowserName);
let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined;
const wsEndpoint = options.useWebSocket ? new Promise<string>(f => wsEndpointCallback = f) : undefined;

View File

@ -292,21 +292,25 @@ export class Registry {
linuxLddDirectories(browserName: BrowserName): string[] {
const browserDirectory = this.browserDirectory(browserName);
if (browserName === 'chromium')
return [path.join(browserDirectory, 'chrome-linux')];
if (browserName === 'firefox')
return [path.join(browserDirectory, 'firefox')];
if (browserName === 'webkit') {
return [
path.join(browserDirectory, 'minibrowser-gtk'),
path.join(browserDirectory, 'minibrowser-gtk', 'bin'),
path.join(browserDirectory, 'minibrowser-gtk', 'lib'),
path.join(browserDirectory, 'minibrowser-wpe'),
path.join(browserDirectory, 'minibrowser-wpe', 'bin'),
path.join(browserDirectory, 'minibrowser-wpe', 'lib'),
];
switch (browserName) {
case 'chromium':
return [path.join(browserDirectory, 'chrome-linux')];
case 'webkit':
case 'webkit-technology-preview':
return [
path.join(browserDirectory, 'minibrowser-gtk'),
path.join(browserDirectory, 'minibrowser-gtk', 'bin'),
path.join(browserDirectory, 'minibrowser-gtk', 'lib'),
path.join(browserDirectory, 'minibrowser-wpe'),
path.join(browserDirectory, 'minibrowser-wpe', 'bin'),
path.join(browserDirectory, 'minibrowser-wpe', 'lib'),
];
case 'firefox':
case 'firefox-stable':
return [path.join(browserDirectory, 'firefox')];
default:
return [];
}
return [];
}
windowsExeAndDllDirectories(browserName: BrowserName): string[] {
@ -345,14 +349,13 @@ export class Registry {
return util.format(urlTemplate, downloadHost, browser.revision);
}
shouldRetain(browserName: BrowserName): boolean {
isSupportedBrowser(browserName: string): boolean {
// We retain browsers if they are found in the descriptor.
// Note, however, that there are older versions out in the wild that rely on
// the "download" field in the browser descriptor and use its value
// to retain and download browsers.
// As of v1.10, we decided to abandon "download" field.
const browser = this._descriptors.find(browser => browser.name === browserName);
return !!browser;
return this._descriptors.some(browser => browser.name === browserName);
}
installByDefault(): BrowserName[] {