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:
parent
c8c92c509d
commit
fd2e65b73c
|
|
@ -3,15 +3,18 @@
|
|||
"browsers": [
|
||||
{
|
||||
"name": "chromium",
|
||||
"revision": "791201"
|
||||
"revision": "791201",
|
||||
"download": true
|
||||
},
|
||||
{
|
||||
"name": "firefox",
|
||||
"revision": "1140"
|
||||
"revision": "1140",
|
||||
"download": true
|
||||
},
|
||||
{
|
||||
"name": "webkit",
|
||||
"revision": "1317"
|
||||
"revision": "1317",
|
||||
"download": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
1
packages/.gitignore
vendored
Normal file
1
packages/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
output
|
||||
|
|
@ -64,8 +64,6 @@ const PACKAGES = {
|
|||
},
|
||||
};
|
||||
|
||||
const cleanupPaths = [];
|
||||
|
||||
// 1. Parse CLI arguments
|
||||
const args = process.argv.slice(2);
|
||||
if (args.some(arg => arg === '--help')) {
|
||||
|
|
@ -81,10 +79,19 @@ if (args.some(arg => arg === '--help')) {
|
|||
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
|
||||
if (!args.some(arg => arg === '--no-cleanup')) {
|
||||
process.on('exit', () => {
|
||||
cleanupPaths.forEach(cleanupPath => rmSync(cleanupPath, {}));
|
||||
rmSync(packagePath, {});
|
||||
});
|
||||
process.on('SIGINT', () => process.exit(2));
|
||||
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 () => {
|
||||
// 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)
|
||||
await copyToPackage(file);
|
||||
await copyToPackage(path.join(ROOT_PATH, file), path.join(packagePath, file));
|
||||
|
||||
// 4. Generate package.json
|
||||
const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json'));
|
||||
|
|
@ -144,7 +149,8 @@ if (!package) {
|
|||
|
||||
// 5. Generate 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));
|
||||
|
||||
// 6. Run npm pack
|
||||
|
|
@ -163,15 +169,11 @@ if (!package) {
|
|||
|
||||
async function writeToPackage(fileName, content) {
|
||||
const toPath = path.join(packagePath, fileName);
|
||||
cleanupPaths.push(toPath);
|
||||
console.error(`- generating: //${path.relative(ROOT_PATH, toPath)}`);
|
||||
await writeFileAsync(toPath, content);
|
||||
}
|
||||
|
||||
async function copyToPackage(fileOrDirectoryName) {
|
||||
const fromPath = path.join(ROOT_PATH, fileOrDirectoryName);
|
||||
const toPath = path.join(packagePath, fileOrDirectoryName);
|
||||
cleanupPaths.push(toPath);
|
||||
async function copyToPackage(fromPath, toPath) {
|
||||
console.error(`- copying: //${path.relative(ROOT_PATH, fromPath)} -> //${path.relative(ROOT_PATH, toPath)}`);
|
||||
await cpAsync(fromPath, toPath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,6 @@
|
|||
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>;
|
||||
export const webkit: types.BrowserType<types.WebKitBrowser>;
|
||||
|
|
@ -14,28 +14,9 @@
|
|||
* 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 errorsFile from 'playwright-chromium/lib/errors.js';
|
||||
|
||||
if (playwright.chromium !== chromium)
|
||||
process.exit(1);
|
||||
|
||||
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);
|
||||
});
|
||||
import testESM from './esm.mjs';
|
||||
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium]);
|
||||
|
|
|
|||
|
|
@ -14,28 +14,9 @@
|
|||
* 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 errorsFile from 'playwright-firefox/lib/errors.js';
|
||||
|
||||
if (playwright.firefox !== firefox)
|
||||
process.exit(1);
|
||||
|
||||
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);
|
||||
});
|
||||
import testESM from './esm.mjs';
|
||||
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [firefox]);
|
||||
|
|
|
|||
|
|
@ -14,28 +14,9 @@
|
|||
* 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 errorsFile from 'playwright-webkit/lib/errors.js';
|
||||
|
||||
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 [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);
|
||||
});
|
||||
import testESM from './esm.mjs';
|
||||
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [webkit]);
|
||||
|
|
|
|||
|
|
@ -18,28 +18,5 @@ import { chromium, firefox, webkit, selectors, devices, errors } from 'playwrigh
|
|||
import playwright from 'playwright';
|
||||
import errorsFile from 'playwright/lib/errors.js';
|
||||
|
||||
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);
|
||||
|
||||
(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);
|
||||
});
|
||||
import testESM from './esm.mjs';
|
||||
testESM({ chromium, firefox, webkit, selectors, devices, errors, playwright, errorsFile }, [chromium, firefox, webkit]);
|
||||
|
|
|
|||
42
packages/installation-tests/esm.mjs
Normal file
42
packages/installation-tests/esm.mjs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,7 @@ NODE_VERSION="$(node --version)"
|
|||
|
||||
function copy_test_scripts {
|
||||
cp "${SCRIPTS_PATH}/sanity.js" .
|
||||
cp "${SCRIPTS_PATH}/esm.mjs" .
|
||||
cp "${SCRIPTS_PATH}/esm-playwright.mjs" .
|
||||
cp "${SCRIPTS_PATH}/esm-playwright-chromium.mjs" .
|
||||
cp "${SCRIPTS_PATH}/esm-playwright-firefox.mjs" .
|
||||
|
|
@ -43,6 +44,7 @@ function run_tests {
|
|||
test_playwright_webkit_should_work
|
||||
test_playwright_firefox_should_work
|
||||
test_playwright_global_installation
|
||||
test_playwright_global_installation_cross_package
|
||||
}
|
||||
|
||||
function test_typescript_types {
|
||||
|
|
@ -77,13 +79,31 @@ function test_playwright_global_installation {
|
|||
exit 1
|
||||
fi
|
||||
copy_test_scripts
|
||||
if node sanity.js playwright chromium 2>/dev/null; then
|
||||
echo "Should not be able to launch chromium without PLAYWRIGHT_BROWSERS_PATH variable!"
|
||||
exit 1
|
||||
fi
|
||||
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright chromium
|
||||
node sanity.js playwright none
|
||||
PLAYWRIGHT_BROWSERS_PATH="${BROWSERS}" node sanity.js playwright
|
||||
}
|
||||
|
||||
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
|
||||
function test_playwright_global_installation_subsequent_installs {
|
||||
|
|
@ -119,9 +139,21 @@ function test_skip_browser_download {
|
|||
function test_playwright_should_work {
|
||||
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
|
||||
node sanity.js playwright chromium firefox webkit
|
||||
node sanity.js playwright
|
||||
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
|
||||
node esm-playwright.mjs
|
||||
fi
|
||||
|
|
@ -130,9 +162,21 @@ function test_playwright_should_work {
|
|||
function test_playwright_chromium_should_work {
|
||||
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
|
||||
node sanity.js playwright-chromium chromium
|
||||
node sanity.js playwright-chromium
|
||||
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
|
||||
node esm-playwright-chromium.mjs
|
||||
fi
|
||||
|
|
@ -141,9 +185,21 @@ function test_playwright_chromium_should_work {
|
|||
function test_playwright_webkit_should_work {
|
||||
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
|
||||
node sanity.js playwright-webkit webkit
|
||||
node sanity.js playwright-webkit
|
||||
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
|
||||
node esm-playwright-webkit.mjs
|
||||
fi
|
||||
|
|
@ -152,9 +208,21 @@ function test_playwright_webkit_should_work {
|
|||
function test_playwright_firefox_should_work {
|
||||
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
|
||||
node sanity.js playwright-firefox firefox
|
||||
node sanity.js playwright-firefox
|
||||
if [[ "${NODE_VERSION}" == *"v14."* ]]; then
|
||||
node esm-playwright-firefox.mjs
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -15,7 +15,16 @@
|
|||
*/
|
||||
|
||||
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);
|
||||
|
||||
|
|
@ -24,12 +33,28 @@ const errors = require(requireName + '/lib/errors');
|
|||
const installer = require(requireName + '/lib/install/installer');
|
||||
|
||||
(async () => {
|
||||
for (const browserType of browsers) {
|
||||
const browser = await playwright[browserType].launch();
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
await page.evaluate(() => navigator.userAgent);
|
||||
await browser.close();
|
||||
for (const browserType of success) {
|
||||
try {
|
||||
const browser = await playwright[browserType].launch();
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
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`);
|
||||
})().catch(err => {
|
||||
|
|
|
|||
20
packages/playwright-chromium/index.d.ts
vendored
20
packages/playwright-chromium/index.d.ts
vendored
|
|
@ -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>;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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']);
|
||||
|
|
@ -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. */
|
||||
20
packages/playwright-firefox/index.d.ts
vendored
20
packages/playwright-firefox/index.d.ts
vendored
|
|
@ -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>;
|
||||
|
|
@ -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']);
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
20
packages/playwright-webkit/index.d.ts
vendored
20
packages/playwright-webkit/index.d.ts
vendored
|
|
@ -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>;
|
||||
|
|
@ -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']);
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
22
packages/playwright/index.d.ts
vendored
22
packages/playwright/index.d.ts
vendored
|
|
@ -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>;
|
||||
|
|
@ -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']);
|
||||
|
|
@ -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;
|
||||
|
|
@ -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);
|
||||
|
|
@ -122,7 +122,8 @@ function revisionURL(browser: BrowserDescriptor, platform = browserPaths.hostPla
|
|||
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}`;
|
||||
if (await existsAsync(browserPath)) {
|
||||
// Already downloaded.
|
||||
|
|
@ -168,8 +169,8 @@ function toMegabytes(bytes: number) {
|
|||
return `${Math.round(mb * 10) / 10} Mb`;
|
||||
}
|
||||
|
||||
export async function canDownload(browserName: BrowserName, browserRevision: string, platform: BrowserPlatform): Promise<boolean> {
|
||||
const url = revisionURL({ name: browserName, revision: browserRevision }, platform);
|
||||
export async function canDownload(browser: BrowserDescriptor, platform: BrowserPlatform): Promise<boolean> {
|
||||
const url = revisionURL(browser, platform);
|
||||
let resolve: (result: boolean) => void = () => {};
|
||||
const promise = new Promise<boolean>(x => resolve = x);
|
||||
const request = httpRequest(url, 'HEAD', response => {
|
||||
|
|
|
|||
|
|
@ -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 BrowserDescriptor = {
|
||||
name: BrowserName,
|
||||
revision: string
|
||||
revision: string,
|
||||
download: boolean,
|
||||
};
|
||||
|
||||
export const hostPlatform = ((): BrowserPlatform => {
|
||||
|
|
|
|||
|
|
@ -52,8 +52,8 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
|
|||
let linkTarget = '';
|
||||
try {
|
||||
linkTarget = (await fsReadFileAsync(linkPath)).toString();
|
||||
const browsers = JSON.parse((await fsReadFileAsync(path.join(linkTarget, 'browsers.json'))).toString())['browsers'];
|
||||
for (const browser of browsers) {
|
||||
const browsersToDownload = await readBrowsersToDownload(linkTarget);
|
||||
for (const browser of browsersToDownload) {
|
||||
const usedBrowserPath = browserPaths.browserDirectory(browsersPath, browser);
|
||||
const browserRevision = parseInt(browser.revision, 10);
|
||||
// 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.
|
||||
const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'] as browserPaths.BrowserDescriptor[];
|
||||
for (const browser of myBrowsers) {
|
||||
const browserPath = browserPaths.browserDirectory(browsersPath, browser);
|
||||
await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser);
|
||||
const myBrowsersToDownload = await readBrowsersToDownload(packagePath);
|
||||
for (const browser of myBrowsersToDownload) {
|
||||
await browserFetcher.downloadBrowserWithProgressBar(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 {
|
||||
const sum = crypto.createHash('sha1');
|
||||
sum.update(data);
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, PlaywrightIniti
|
|||
const deviceDescriptors = Object.entries(playwright.devices)
|
||||
.map(([name, descriptor]) => ({ name, descriptor }));
|
||||
super(scope, playwright, 'Playwright', {
|
||||
chromium: new BrowserTypeDispatcher(scope, playwright.chromium!),
|
||||
firefox: new BrowserTypeDispatcher(scope, playwright.firefox!),
|
||||
webkit: new BrowserTypeDispatcher(scope, playwright.webkit!),
|
||||
chromium: new BrowserTypeDispatcher(scope, playwright.chromium),
|
||||
firefox: new BrowserTypeDispatcher(scope, playwright.firefox),
|
||||
webkit: new BrowserTypeDispatcher(scope, playwright.webkit),
|
||||
electron: electron ? new ElectronDispatcher(scope, electron) : undefined,
|
||||
deviceDescriptors,
|
||||
selectors: new SelectorsDispatcher(scope, playwright.selectors),
|
||||
|
|
|
|||
|
|
@ -34,24 +34,21 @@ export class Playwright {
|
|||
readonly selectors = selectors;
|
||||
readonly devices: types.Devices;
|
||||
readonly errors: { TimeoutError: typeof TimeoutError };
|
||||
readonly chromium: (Chromium|undefined);
|
||||
readonly firefox: (Firefox|undefined);
|
||||
readonly webkit: (WebKit|undefined);
|
||||
readonly chromium: Chromium;
|
||||
readonly firefox: Firefox;
|
||||
readonly webkit: WebKit;
|
||||
|
||||
constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {
|
||||
this.devices = DeviceDescriptors;
|
||||
this.errors = { TimeoutError };
|
||||
|
||||
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');
|
||||
if (firefox)
|
||||
this.firefox = new Firefox(packagePath, firefox);
|
||||
this.firefox = new Firefox(packagePath, firefox!);
|
||||
|
||||
const webkit = browsers.find(browser => browser.name === 'webkit');
|
||||
if (webkit)
|
||||
this.webkit = new WebKit(packagePath, webkit);
|
||||
this.webkit = new WebKit(packagePath, webkit!);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ async function checkRangeAvailability(fromRevision, toRevision, stopWhenAllAvail
|
|||
* @return {boolean}
|
||||
*/
|
||||
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 allAvailable = availability.every(e => !!e);
|
||||
const values = [name + ' ' + (allAvailable ? colors.green + revision + colors.reset : revision)];
|
||||
|
|
|
|||
Loading…
Reference in a new issue