2019-11-19 05:18:28 +03:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
2019-12-11 00:21:51 +03:00
|
|
|
* Modifications copyright (c) Microsoft Corporation.
|
2019-11-19 05:18:28 +03:00
|
|
|
*
|
|
|
|
* 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 path = require('path');
|
|
|
|
const {TestServer} = require('../utils/testserver/');
|
|
|
|
const {TestRunner, Reporter} = require('../utils/testrunner/');
|
|
|
|
const utils = require('./utils');
|
|
|
|
|
|
|
|
let parallel = 1;
|
2020-01-25 03:15:41 +03:00
|
|
|
if (process.env.PW_PARALLEL_TESTS)
|
|
|
|
parallel = parseInt(process.env.PW_PARALLEL_TESTS.trim(), 10);
|
2019-11-19 05:18:28 +03:00
|
|
|
const parallelArgIndex = process.argv.indexOf('-j');
|
|
|
|
if (parallelArgIndex !== -1)
|
|
|
|
parallel = parseInt(process.argv[parallelArgIndex + 1], 10);
|
|
|
|
require('events').defaultMaxListeners *= parallel;
|
|
|
|
|
2020-01-14 04:16:05 +03:00
|
|
|
let timeout = process.env.CI ? 30 * 1000 : 10 * 1000;
|
2019-11-19 05:18:28 +03:00
|
|
|
if (!isNaN(process.env.TIMEOUT))
|
2020-02-10 21:08:51 +03:00
|
|
|
timeout = parseInt(process.env.TIMEOUT * 1000, 10);
|
2019-11-19 05:18:28 +03:00
|
|
|
const testRunner = new TestRunner({
|
|
|
|
timeout,
|
|
|
|
parallel,
|
|
|
|
breakOnFailure: process.argv.indexOf('--break-on-failure') !== -1,
|
|
|
|
});
|
|
|
|
const {describe, fdescribe, beforeAll, afterAll, beforeEach, afterEach} = testRunner;
|
|
|
|
|
|
|
|
console.log('Testing on Node', process.version);
|
|
|
|
|
|
|
|
beforeAll(async state => {
|
|
|
|
const assetsPath = path.join(__dirname, 'assets');
|
|
|
|
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
|
|
|
|
2020-01-11 03:03:10 +03:00
|
|
|
const port = 8907 + state.parallelIndex * 3;
|
2019-11-19 05:18:28 +03:00
|
|
|
state.server = await TestServer.create(assetsPath, port);
|
|
|
|
state.server.enableHTTPCache(cachedPath);
|
|
|
|
state.server.PORT = port;
|
|
|
|
state.server.PREFIX = `http://localhost:${port}`;
|
|
|
|
state.server.CROSS_PROCESS_PREFIX = `http://127.0.0.1:${port}`;
|
|
|
|
state.server.EMPTY_PAGE = `http://localhost:${port}/empty.html`;
|
|
|
|
|
|
|
|
const httpsPort = port + 1;
|
|
|
|
state.httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort);
|
|
|
|
state.httpsServer.enableHTTPCache(cachedPath);
|
|
|
|
state.httpsServer.PORT = httpsPort;
|
|
|
|
state.httpsServer.PREFIX = `https://localhost:${httpsPort}`;
|
|
|
|
state.httpsServer.CROSS_PROCESS_PREFIX = `https://127.0.0.1:${httpsPort}`;
|
|
|
|
state.httpsServer.EMPTY_PAGE = `https://localhost:${httpsPort}/empty.html`;
|
2020-01-11 03:03:10 +03:00
|
|
|
|
|
|
|
const sourcePort = port + 2;
|
|
|
|
state.sourceServer = await TestServer.create(path.join(__dirname, '..'), sourcePort);
|
|
|
|
state.sourceServer.PORT = sourcePort;
|
|
|
|
state.sourceServer.PREFIX = `http://localhost:${sourcePort}`;
|
2019-11-19 05:18:28 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async({server, httpsServer}) => {
|
|
|
|
await Promise.all([
|
|
|
|
server.stop(),
|
|
|
|
httpsServer.stop(),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async({server, httpsServer}) => {
|
|
|
|
server.reset();
|
|
|
|
httpsServer.reset();
|
|
|
|
});
|
|
|
|
|
2020-01-17 04:46:50 +03:00
|
|
|
const products = ['WebKit', 'Firefox', 'Chromium'];
|
|
|
|
let product;
|
|
|
|
let events;
|
2020-02-13 03:13:48 +03:00
|
|
|
let missingCoverage;
|
2019-12-19 01:32:20 +03:00
|
|
|
if (process.env.BROWSER === 'firefox') {
|
2020-01-17 04:46:50 +03:00
|
|
|
product = 'Firefox';
|
|
|
|
events = {
|
|
|
|
...require('../lib/events').Events,
|
|
|
|
...require('../lib/chromium/events').Events,
|
|
|
|
};
|
2020-03-04 03:09:32 +03:00
|
|
|
missingCoverage = ['browserContext.setGeolocation', 'page.setOfflineMode'];
|
2019-12-19 01:32:20 +03:00
|
|
|
} else if (process.env.BROWSER === 'webkit') {
|
2020-01-17 04:46:50 +03:00
|
|
|
product = 'WebKit';
|
|
|
|
events = require('../lib/events').Events;
|
2020-02-13 03:13:48 +03:00
|
|
|
missingCoverage = ['browserContext.clearPermissions'];
|
2019-12-19 01:32:20 +03:00
|
|
|
} else {
|
2020-01-17 04:46:50 +03:00
|
|
|
product = 'Chromium';
|
|
|
|
events = require('../lib/events').Events;
|
2020-02-13 03:13:48 +03:00
|
|
|
missingCoverage = [];
|
2019-12-19 01:32:20 +03:00
|
|
|
}
|
2019-11-19 05:18:28 +03:00
|
|
|
|
2020-01-17 04:46:50 +03:00
|
|
|
describe(product, () => {
|
|
|
|
testRunner.loadTests(require('./playwright.spec.js'), {
|
|
|
|
product,
|
|
|
|
playwrightPath: utils.projectRoot(),
|
|
|
|
testRunner,
|
|
|
|
});
|
|
|
|
if (process.env.COVERAGE) {
|
|
|
|
const api = require('../lib/api');
|
|
|
|
const filteredApi = {};
|
|
|
|
Object.keys(api).forEach(name => {
|
|
|
|
if (products.some(p => name.startsWith(p)) && !name.startsWith(product))
|
|
|
|
return;
|
|
|
|
filteredApi[name] = api[name];
|
|
|
|
});
|
2020-02-13 03:13:48 +03:00
|
|
|
utils.recordAPICoverage(testRunner, filteredApi, events, missingCoverage);
|
2020-01-17 04:46:50 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-19 01:32:20 +03:00
|
|
|
if (process.env.CI && testRunner.hasFocusedTestsOrSuites()) {
|
|
|
|
console.error('ERROR: "focused" tests/suites are prohibitted on bots. Remove any "fit"/"fdescribe" declarations.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-11-19 05:18:28 +03:00
|
|
|
|
2019-12-19 01:32:20 +03:00
|
|
|
new Reporter(testRunner, {
|
|
|
|
verbose: process.argv.includes('--verbose'),
|
|
|
|
summary: !process.argv.includes('--verbose'),
|
|
|
|
showSlowTests: process.env.CI ? 5 : 0,
|
2020-03-03 01:57:09 +03:00
|
|
|
showMarkedAsFailingTests: 10,
|
2019-12-19 01:32:20 +03:00
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
|
2019-12-19 01:32:20 +03:00
|
|
|
// await utils.initializeFlakinessDashboardIfNeeded(testRunner);
|
|
|
|
testRunner.run().then(result => {
|
2020-01-14 02:30:16 +03:00
|
|
|
process.exit(result.exitCode);
|
2019-12-19 01:32:20 +03:00
|
|
|
});
|
2019-11-19 05:18:28 +03:00
|
|
|
|