api: export all browsers from every package (#3128)

This makes it easier to reason about our packages.
The only difference is what each package downloads.
When the browser is not downloaded, it will fail to launch.

Each browser gets a 'download' attribute in the browser.json file.
This commit is contained in:
Dmitry Gozman 2020-07-24 16:36:00 -07:00 committed by GitHub
parent c8c92c509d
commit fd2e65b73c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 223 additions and 483 deletions

View file

@ -3,15 +3,18 @@
"browsers": [ "browsers": [
{ {
"name": "chromium", "name": "chromium",
"revision": "791201" "revision": "791201",
"download": true
}, },
{ {
"name": "firefox", "name": "firefox",
"revision": "1140" "revision": "1140",
"download": true
}, },
{ {
"name": "webkit", "name": "webkit",
"revision": "1317" "revision": "1317",
"download": true
} }
] ]
} }

1
packages/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
output

View file

@ -64,8 +64,6 @@ const PACKAGES = {
}, },
}; };
const cleanupPaths = [];
// 1. Parse CLI arguments // 1. Parse CLI arguments
const args = process.argv.slice(2); const args = process.argv.slice(2);
if (args.some(arg => arg === '--help')) { if (args.some(arg => arg === '--help')) {
@ -81,10 +79,19 @@ if (args.some(arg => arg === '--help')) {
process.exit(1); process.exit(1);
} }
const packageName = args[0];
const outputPath = path.resolve(args[1]);
const packagePath = path.join(__dirname, 'output', packageName);
const package = PACKAGES[packageName];
if (!package) {
console.log(`ERROR: unknown package ${packageName}`);
process.exit(1);
}
// 2. Setup cleanup if needed // 2. Setup cleanup if needed
if (!args.some(arg => arg === '--no-cleanup')) { if (!args.some(arg => arg === '--no-cleanup')) {
process.on('exit', () => { process.on('exit', () => {
cleanupPaths.forEach(cleanupPath => rmSync(cleanupPath, {})); rmSync(packagePath, {});
}); });
process.on('SIGINT', () => process.exit(2)); process.on('SIGINT', () => process.exit(2));
process.on('SIGHUP', () => process.exit(3)); process.on('SIGHUP', () => process.exit(3));
@ -99,19 +106,17 @@ if (!args.some(arg => arg === '--no-cleanup')) {
}); });
} }
const packageName = args[0];
const outputPath = path.resolve(args[1]);
const packagePath = path.join(__dirname, packageName);
const package = PACKAGES[packageName];
if (!package) {
console.log(`ERROR: unknown package ${packageName}`);
process.exit(1);
}
(async () => { (async () => {
// 3. Copy package files. // 3. Copy package files.
rmSync(packagePath, {});
fs.mkdirSync(packagePath, { recursive: true });
await copyToPackage(path.join(__dirname, 'common') + path.sep, packagePath + path.sep);
if (fs.existsSync(path.join(__dirname, packageName))) {
// Copy package-specific files, these can overwrite common ones.
await copyToPackage(path.join(__dirname, packageName) + path.sep, packagePath + path.sep);
}
for (const file of package.files) for (const file of package.files)
await copyToPackage(file); await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file));
// 4. Generate package.json // 4. Generate package.json
const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json')); const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json'));
@ -144,7 +149,8 @@ if (!package) {
// 5. Generate browsers.json // 5. Generate browsers.json
const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json')); const browsersJSON = require(path.join(ROOT_PATH, 'browsers.json'));
browsersJSON.browsers = browsersJSON.browsers.filter(browser => package.browsers.includes(browser.name)); for (const browser of browsersJSON.browsers)
browser.download = package.browsers.includes(browser.name);
await writeToPackage('browsers.json', JSON.stringify(browsersJSON, null, 2)); await writeToPackage('browsers.json', JSON.stringify(browsersJSON, null, 2));
// 6. Run npm pack // 6. Run npm pack
@ -163,15 +169,11 @@ if (!package) {
async function writeToPackage(fileName, content) { async function writeToPackage(fileName, content) {
const toPath = path.join(packagePath, fileName); const toPath = path.join(packagePath, fileName);
cleanupPaths.push(toPath);
console.error(`- generating: //${path.relative(ROOT_PATH, toPath)}`); console.error(`- generating: //${path.relative(ROOT_PATH, toPath)}`);
await writeFileAsync(toPath, content); await writeFileAsync(toPath, content);
} }
async function copyToPackage(fileOrDirectoryName) { async function copyToPackage(fromPath, toPath) {
const fromPath = path.join(ROOT_PATH, fileOrDirectoryName);
const toPath = path.join(packagePath, fileOrDirectoryName);
cleanupPaths.push(toPath);
console.error(`- copying: //${path.relative(ROOT_PATH, fromPath)} -> //${path.relative(ROOT_PATH, toPath)}`); console.error(`- copying: //${path.relative(ROOT_PATH, fromPath)} -> //${path.relative(ROOT_PATH, toPath)}`);
await cpAsync(fromPath, toPath); await cpAsync(fromPath, toPath);
} }

View file

@ -17,6 +17,6 @@
import * as types from './types/types'; import * as types from './types/types';
export * from './types/types'; export * from './types/types';
export const webkit: types.BrowserType<types.WebKitBrowser>;
export const chromium: types.BrowserType<types.ChromiumBrowser>; export const chromium: types.BrowserType<types.ChromiumBrowser>;
export const firefox: types.BrowserType<types.FirefoxBrowser>; export const firefox: types.BrowserType<types.FirefoxBrowser>;
export const webkit: types.BrowserType<types.WebKitBrowser>;

View file

@ -14,28 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { chromium, selectors, devices, errors } from 'playwright-chromium'; import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-chromium';
import playwright from 'playwright-chromium'; import playwright from 'playwright-chromium';
import errorsFile from 'playwright-chromium/lib/errors.js'; import errorsFile from 'playwright-chromium/lib/errors.js';
if (playwright.chromium !== chromium) import testESM from './esm.mjs';
process.exit(1); testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium]);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);
(async () => {
for (const browserType of [chromium]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View file

@ -14,28 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { firefox, selectors, devices, errors } from 'playwright-firefox'; import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-firefox';
import playwright from 'playwright-firefox'; import playwright from 'playwright-firefox';
import errorsFile from 'playwright-firefox/lib/errors.js'; import errorsFile from 'playwright-firefox/lib/errors.js';
if (playwright.firefox !== firefox) import testESM from './esm.mjs';
process.exit(1); testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [firefox]);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);
(async () => {
for (const browserType of [firefox]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View file

@ -14,28 +14,9 @@
* limitations under the License. * limitations under the License.
*/ */
import { webkit, selectors, devices, errors } from 'playwright-webkit'; import { chromium, firefox, webkit, selectors, devices, errors } from 'playwright-webkit';
import playwright from 'playwright-webkit'; import playwright from 'playwright-webkit';
import errorsFile from 'playwright-webkit/lib/errors.js'; import errorsFile from 'playwright-webkit/lib/errors.js';
if (playwright.webkit !== webkit) import testESM from './esm.mjs';
process.exit(1); testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [webkit]);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);
(async () => {
for (const browserType of [webkit]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View file

@ -18,28 +18,5 @@ import { chromium, firefox, webkit, selectors, devices, errors } from 'playwrigh
import playwright from 'playwright'; import playwright from 'playwright';
import errorsFile from 'playwright/lib/errors.js'; import errorsFile from 'playwright/lib/errors.js';
if (playwright.chromium !== chromium) import testESM from './esm.mjs';
process.exit(1); testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium, firefox, webkit]);
if (playwright.firefox !== firefox)
process.exit(1);
if (playwright.webkit !== webkit)
process.exit(1);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);
(async () => {
for (const browserType of [chromium, firefox, webkit]) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View file

@ -0,0 +1,42 @@
/**
* 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 default async function testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, browsers) {
if (playwright.chromium !== chromium)
process.exit(1);
if (playwright.firefox !== firefox)
process.exit(1);
if (playwright.webkit !== webkit)
process.exit(1);
if (playwright.errors !== errors)
process.exit(1);
if (errors.TimeoutError !== errorsFile.TimeoutError)
process.exit(1);
try {
for (const browserType of browsers) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
} catch (err) {
console.error(err);
process.exit(1);
}
}

View file

@ -28,6 +28,7 @@ NODE_VERSION="$(node --version)"
function copy_test_scripts { function copy_test_scripts {
cp "${SCRIPTS_PATH}/sanity.js" . cp "${SCRIPTS_PATH}/sanity.js" .
cp "${SCRIPTS_PATH}/esm.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright.mjs" . cp "${SCRIPTS_PATH}/esm-playwright.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" . cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" . cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" .
@ -43,6 +44,7 @@ function run_tests {
test_playwright_webkit_should_work test_playwright_webkit_should_work
test_playwright_firefox_should_work test_playwright_firefox_should_work
test_playwright_global_installation test_playwright_global_installation
test_playwright_global_installation_cross_package
} }
function test_typescript_types { function test_typescript_types {
@ -77,13 +79,31 @@ function test_playwright_global_installation {
exit 1 exit 1
fi fi
copy_test_scripts copy_test_scripts
if node sanity.js playwright chromium 2>/dev/null; then node sanity.js playwright none
echo "Should not be able to launch chromium without PLAYWRIGHT_BROWSERS_PATH variable!" PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright
exit 1
fi
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright chromium
} }
function test_playwright_global_installation_cross_package {
initialize_test "${FUNCNAME[0]}"
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_FIREFOX_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_WEBKIT_TGZ}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install ${PLAYWRIGHT_CHROMIUM_TGZ}
local BROWSERS="$(pwd -P)/browsers"
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" npm install ${PLAYWRIGHT_TGZ}
if [[ ! -d "${BROWSERS}" ]]; then
echo "Directory for shared browsers was not created!"
exit 1
fi
copy_test_scripts
# Every package should be able to launch.
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-chromium all
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-firefox all
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright-webkit all
}
# @see https://github.com/microsoft/playwright/issues/1651 # @see https://github.com/microsoft/playwright/issues/1651
function test_playwright_global_installation_subsequent_installs { function test_playwright_global_installation_subsequent_installs {
@ -119,9 +139,21 @@ function test_skip_browser_download {
function test_playwright_should_work { function test_playwright_should_work {
initialize_test "${FUNCNAME[0]}" initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_TGZ} OUTPUT=$(npm install ${PLAYWRIGHT_TGZ})
if [[ "${OUTPUT}" != *"chromium"* ]]; then
echo "ERROR: should download chromium"
exit 1
fi
if [[ "${OUTPUT}" != *"firefox"* ]]; then
echo "ERROR: should download firefox"
exit 1
fi
if [[ "${OUTPUT}" != *"webkit"* ]]; then
echo "ERROR: should download webkit"
exit 1
fi
copy_test_scripts copy_test_scripts
node sanity.js playwright chromium firefox webkit node sanity.js playwright
if [[ "${NODE_VERSION}" == *"v14."* ]]; then if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright.mjs node esm-playwright.mjs
fi fi
@ -130,9 +162,21 @@ function test_playwright_should_work {
function test_playwright_chromium_should_work { function test_playwright_chromium_should_work {
initialize_test "${FUNCNAME[0]}" initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_CHROMIUM_TGZ} OUTPUT=$(npm install ${PLAYWRIGHT_CHROMIUM_TGZ})
if [[ "${OUTPUT}" != *"chromium"* ]]; then
echo "ERROR: should download chromium"
exit 1
fi
if [[ "${OUTPUT}" == *"firefox"* ]]; then
echo "ERROR: should not download firefox"
exit 1
fi
if [[ "${OUTPUT}" == *"webkit"* ]]; then
echo "ERROR: should not download webkit"
exit 1
fi
copy_test_scripts copy_test_scripts
node sanity.js playwright-chromium chromium node sanity.js playwright-chromium
if [[ "${NODE_VERSION}" == *"v14."* ]]; then if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-chromium.mjs node esm-playwright-chromium.mjs
fi fi
@ -141,9 +185,21 @@ function test_playwright_chromium_should_work {
function test_playwright_webkit_should_work { function test_playwright_webkit_should_work {
initialize_test "${FUNCNAME[0]}" initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_WEBKIT_TGZ} OUTPUT=$(npm install ${PLAYWRIGHT_WEBKIT_TGZ})
if [[ "${OUTPUT}" == *"chromium"* ]]; then
echo "ERROR: should not download chromium"
exit 1
fi
if [[ "${OUTPUT}" == *"firefox"* ]]; then
echo "ERROR: should not download firefox"
exit 1
fi
if [[ "${OUTPUT}" != *"webkit"* ]]; then
echo "ERROR: should download webkit"
exit 1
fi
copy_test_scripts copy_test_scripts
node sanity.js playwright-webkit webkit node sanity.js playwright-webkit
if [[ "${NODE_VERSION}" == *"v14."* ]]; then if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-webkit.mjs node esm-playwright-webkit.mjs
fi fi
@ -152,9 +208,21 @@ function test_playwright_webkit_should_work {
function test_playwright_firefox_should_work { function test_playwright_firefox_should_work {
initialize_test "${FUNCNAME[0]}" initialize_test "${FUNCNAME[0]}"
npm install ${PLAYWRIGHT_FIREFOX_TGZ} OUTPUT=$(npm install ${PLAYWRIGHT_FIREFOX_TGZ})
if [[ "${OUTPUT}" == *"chromium"* ]]; then
echo "ERROR: should not download chromium"
exit 1
fi
if [[ "${OUTPUT}" != *"firefox"* ]]; then
echo "ERROR: should download firefox"
exit 1
fi
if [[ "${OUTPUT}" == *"webkit"* ]]; then
echo "ERROR: should not download webkit"
exit 1
fi
copy_test_scripts copy_test_scripts
node sanity.js playwright-firefox firefox node sanity.js playwright-firefox
if [[ "${NODE_VERSION}" == *"v14."* ]]; then if [[ "${NODE_VERSION}" == *"v14."* ]]; then
node esm-playwright-firefox.mjs node esm-playwright-firefox.mjs
fi fi

View file

@ -15,7 +15,16 @@
*/ */
const requireName = process.argv[2]; const requireName = process.argv[2];
const browsers = process.argv.slice(3); let success = {
'playwright': ['chromium', 'firefox', 'webkit'],
'playwright-chromium': ['chromium'],
'playwright-firefox': ['firefox'],
'playwright-webkit': ['webkit'],
}[requireName];
if (process.argv[3] === 'none')
success = [];
if (process.argv[3] === 'all')
success = ['chromium', 'firefox', 'webkit'];
const playwright = require(requireName); const playwright = require(requireName);
@ -24,12 +33,28 @@ const errors = require(requireName + '/lib/errors');
const installer = require(requireName + '/lib/install/installer'); const installer = require(requireName + '/lib/install/installer');
(async () => { (async () => {
for (const browserType of browsers) { for (const browserType of success) {
const browser = await playwright[browserType].launch(); try {
const context = await browser.newContext(); const browser = await playwright[browserType].launch();
const page = await context.newPage(); const context = await browser.newContext();
await page.evaluate(() => navigator.userAgent); const page = await context.newPage();
await browser.close(); await page.evaluate(() => navigator.userAgent);
await browser.close();
} catch (e) {
console.error(`Should be able to launch ${browserType} from ${requireName}`);
console.error(err);
process.exit(1);
}
}
const fail = ['chromium', 'webkit', 'firefox'].filter(x => !success.includes(x));
for (const browserType of fail) {
try {
await playwright[browserType].launch();
console.error(`Should not be able to launch ${browserType} from ${requireName}`);
process.exit(1);
} catch (e) {
// All good.
}
} }
console.log(`require SUCCESS`); console.log(`require SUCCESS`);
})().catch(err => { })().catch(err => {

View file

@ -1,20 +0,0 @@
/**
* 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.
*/
import * as types from './types/types';
export * from './types/types';
export const chromium: types.BrowserType<types.ChromiumBrowser>;

View file

@ -1,23 +0,0 @@
/**
* 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.
*/
import playwright from './index.js';
export const chromium = playwright.chromium;
export const selectors = playwright.selectors;
export const devices = playwright.devices;
export const errors = playwright.errors;
export default playwright;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { Playwright } = require('./lib/server/playwright');
module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);

View file

@ -1,17 +0,0 @@
/**
* 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.
*/
/* NOTE: playwright-core does not install browsers by design. */

View file

@ -1,20 +0,0 @@
/**
* 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.
*/
import * as types from './types/types';
export * from './types/types';
export const firefox: types.BrowserType<types.FirefoxBrowser>;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { Playwright } = require('./lib/server/playwright');
module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);

View file

@ -1,23 +0,0 @@
/**
* 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.
*/
import playwright from './index.js';
export const firefox = playwright.firefox;
export const selectors = playwright.selectors;
export const devices = playwright.devices;
export const errors = playwright.errors;
export default playwright;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { installBrowsersWithProgressBar } = require('./lib/install/installer');
installBrowsersWithProgressBar(__dirname);

View file

@ -1,20 +0,0 @@
/**
* 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.
*/
import * as types from './types/types';
export * from './types/types';
export const webkit: types.BrowserType<types.WebKitBrowser>;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { Playwright } = require('./lib/server/playwright');
module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);

View file

@ -1,23 +0,0 @@
/**
* 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.
*/
import playwright from './index.js';
export const webkit = playwright.webkit;
export const selectors = playwright.selectors;
export const devices = playwright.devices;
export const errors = playwright.errors;
export default playwright;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { installBrowsersWithProgressBar } = require('./lib/install/installer');
installBrowsersWithProgressBar(__dirname);

View file

@ -1,22 +0,0 @@
/**
* 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.
*/
import * as types from './types/types';
export * from './types/types';
export const webkit: types.BrowserType<types.WebKitBrowser>;
export const chromium: types.BrowserType<types.ChromiumBrowser>;
export const firefox: types.BrowserType<types.FirefoxBrowser>;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { Playwright } = require('./lib/server/playwright');
module.exports = new Playwright(__dirname, require('./browsers.json')['browsers']);

View file

@ -1,25 +0,0 @@
/**
* 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.
*/
import playwright from './index.js';
export const chromium = playwright.chromium;
export const firefox = playwright.firefox;
export const webkit = playwright.webkit;
export const selectors = playwright.selectors;
export const devices = playwright.devices;
export const errors = playwright.errors;
export default playwright;

View file

@ -1,19 +0,0 @@
/**
* 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.
*/
const { installBrowsersWithProgressBar } = require('./lib/install/installer');
installBrowsersWithProgressBar(__dirname);

View file

@ -122,7 +122,8 @@ function revisionURL(browser: BrowserDescriptor, platform = browserPaths.hostPla
return util.format(urlTemplate, serverHost, browser.revision); return util.format(urlTemplate, serverHost, browser.revision);
} }
export async function downloadBrowserWithProgressBar(browserPath: string, browser: BrowserDescriptor): Promise<boolean> { export async function downloadBrowserWithProgressBar(browsersPath: string, browser: BrowserDescriptor): Promise<boolean> {
const browserPath = browserPaths.browserDirectory(browsersPath, browser);
const progressBarName = `${browser.name} v${browser.revision}`; const progressBarName = `${browser.name} v${browser.revision}`;
if (await existsAsync(browserPath)) { if (await existsAsync(browserPath)) {
// Already downloaded. // Already downloaded.
@ -168,8 +169,8 @@ function toMegabytes(bytes: number) {
return `${Math.round(mb * 10) / 10} Mb`; return `${Math.round(mb * 10) / 10} Mb`;
} }
export async function canDownload(browserName: BrowserName, browserRevision: string, platform: BrowserPlatform): Promise<boolean> { export async function canDownload(browser: BrowserDescriptor, platform: BrowserPlatform): Promise<boolean> {
const url = revisionURL({ name: browserName, revision: browserRevision }, platform); const url = revisionURL(browser, platform);
let resolve: (result: boolean) => void = () => {}; let resolve: (result: boolean) => void = () => {};
const promise = new Promise<boolean>(x => resolve = x); const promise = new Promise<boolean>(x => resolve = x);
const request = httpRequest(url, 'HEAD', response => { const request = httpRequest(url, 'HEAD', response => {

View file

@ -24,7 +24,8 @@ export type BrowserName = 'chromium'|'webkit'|'firefox';
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'ubuntu18.04'|'ubuntu20.04'; export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'ubuntu18.04'|'ubuntu20.04';
export type BrowserDescriptor = { export type BrowserDescriptor = {
name: BrowserName, name: BrowserName,
revision: string revision: string,
download: boolean,
}; };
export const hostPlatform = ((): BrowserPlatform => { export const hostPlatform = ((): BrowserPlatform => {

View file

@ -52,8 +52,8 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
let linkTarget = ''; let linkTarget = '';
try { try {
linkTarget = (await fsReadFileAsync(linkPath)).toString(); linkTarget = (await fsReadFileAsync(linkPath)).toString();
const browsers = JSON.parse((await fsReadFileAsync(path.join(linkTarget, 'browsers.json'))).toString())['browsers']; const browsersToDownload = await readBrowsersToDownload(linkTarget);
for (const browser of browsers) { for (const browser of browsersToDownload) {
const usedBrowserPath = browserPaths.browserDirectory(browsersPath, browser); const usedBrowserPath = browserPaths.browserDirectory(browsersPath, browser);
const browserRevision = parseInt(browser.revision, 10); const browserRevision = parseInt(browser.revision, 10);
// Old browser installations don't have marker file. // Old browser installations don't have marker file.
@ -82,14 +82,20 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
} }
// 3. Install missing browsers for this package. // 3. Install missing browsers for this package.
const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[]; const myBrowsersToDownload = await readBrowsersToDownload(packagePath);
for (const browser of myBrowsers) { for (const browser of myBrowsersToDownload) {
const browserPath = browserPaths.browserDirectory(browsersPath, browser); await browserFetcher.downloadBrowserWithProgressBar(browsersPath, browser);
await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser);
await fsWriteFileAsync(browserPaths.markerFilePath(browsersPath, browser), ''); await fsWriteFileAsync(browserPaths.markerFilePath(browsersPath, browser), '');
} }
} }
async function readBrowsersToDownload(packagePath: string) {
const browsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[];
// Older versions do not have "download" field. We assume they need all browsers
// from the list. So we want to skip all browsers that are explicitly marked as "download: false".
return browsers.filter(browser => browser.download !== false);
}
function sha1(data: string): string { function sha1(data: string): string {
const sum = crypto.createHash('sha1'); const sum = crypto.createHash('sha1');
sum.update(data); sum.update(data);

View file

@ -28,9 +28,9 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, PlaywrightIniti
const deviceDescriptors = Object.entries(playwright.devices) const deviceDescriptors = Object.entries(playwright.devices)
.map(([name, descriptor]) => ({ name, descriptor })); .map(([name, descriptor]) => ({ name, descriptor }));
super(scope, playwright, 'Playwright', { super(scope, playwright, 'Playwright', {
chromium: new BrowserTypeDispatcher(scope, playwright.chromium!), chromium: new BrowserTypeDispatcher(scope, playwright.chromium),
firefox: new BrowserTypeDispatcher(scope, playwright.firefox!), firefox: new BrowserTypeDispatcher(scope, playwright.firefox),
webkit: new BrowserTypeDispatcher(scope, playwright.webkit!), webkit: new BrowserTypeDispatcher(scope, playwright.webkit),
electron: electron ? new ElectronDispatcher(scope, electron) : undefined, electron: electron ? new ElectronDispatcher(scope, electron) : undefined,
deviceDescriptors, deviceDescriptors,
selectors: new SelectorsDispatcher(scope, playwright.selectors), selectors: new SelectorsDispatcher(scope, playwright.selectors),

View file

@ -34,24 +34,21 @@ export class Playwright {
readonly selectors = selectors; readonly selectors = selectors;
readonly devices: types.Devices; readonly devices: types.Devices;
readonly errors: { TimeoutError: typeof TimeoutError }; readonly errors: { TimeoutError: typeof TimeoutError };
readonly chromium: (Chromium|undefined); readonly chromium: Chromium;
readonly firefox: (Firefox|undefined); readonly firefox: Firefox;
readonly webkit: (WebKit|undefined); readonly webkit: WebKit;
constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) { constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {
this.devices = DeviceDescriptors; this.devices = DeviceDescriptors;
this.errors = { TimeoutError }; this.errors = { TimeoutError };
const chromium = browsers.find(browser => browser.name === 'chromium'); const chromium = browsers.find(browser => browser.name === 'chromium');
if (chromium) this.chromium = new Chromium(packagePath, chromium!);
this.chromium = new Chromium(packagePath, chromium);
const firefox = browsers.find(browser => browser.name === 'firefox'); const firefox = browsers.find(browser => browser.name === 'firefox');
if (firefox) this.firefox = new Firefox(packagePath, firefox!);
this.firefox = new Firefox(packagePath, firefox);
const webkit = browsers.find(browser => browser.name === 'webkit'); const webkit = browsers.find(browser => browser.name === 'webkit');
if (webkit) this.webkit = new WebKit(packagePath, webkit!);
this.webkit = new WebKit(packagePath, webkit);
} }
} }

View file

@ -106,7 +106,7 @@ async function checkRangeAvailability(fromRevision, toRevision, stopWhenAllAvail
* @return {boolean} * @return {boolean}
*/ */
async function checkAndDrawRevisionAvailability(table, name, revision) { async function checkAndDrawRevisionAvailability(table, name, revision) {
const promises = fetcherOptions.map(platform => browserFetcher.canDownload(name, revision, platform)); const promises = fetcherOptions.map(platform => browserFetcher.canDownload({ name, revision, download: true }, platform));
const availability = await Promise.all(promises); const availability = await Promise.all(promises);
const allAvailable = availability.every(e => !!e); const allAvailable = availability.every(e => !!e);
const values = [name + ' ' + (allAvailable ? colors.green + revision + colors.reset : revision)]; const values = [name + ' ' + (allAvailable ? colors.green + revision + colors.reset : revision)];