2017-06-15 15:15:25 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-08-02 19:06:47 +00:00
|
|
|
const path = require('path');
|
2018-09-24 19:46:39 +00:00
|
|
|
const {TestServer} = require('../utils/testserver/');
|
2019-01-24 06:04:42 +00:00
|
|
|
const {TestRunner, Reporter} = require('../utils/testrunner/');
|
2018-08-09 23:51:12 +00:00
|
|
|
const utils = require('./utils');
|
2018-03-16 22:33:31 +00:00
|
|
|
|
2017-12-12 21:34:21 +00:00
|
|
|
let parallel = 1;
|
|
|
|
if (process.env.PPTR_PARALLEL_TESTS)
|
|
|
|
parallel = parseInt(process.env.PPTR_PARALLEL_TESTS.trim(), 10);
|
|
|
|
const parallelArgIndex = process.argv.indexOf('-j');
|
|
|
|
if (parallelArgIndex !== -1)
|
|
|
|
parallel = parseInt(process.argv[parallelArgIndex + 1], 10);
|
2018-01-04 20:08:35 +00:00
|
|
|
require('events').defaultMaxListeners *= parallel;
|
2017-12-08 00:37:22 +00:00
|
|
|
|
2019-02-05 21:38:56 +00:00
|
|
|
// Timeout to 20 seconds on Appveyor instances.
|
|
|
|
let timeout = process.env.APPVEYOR ? 20 * 1000 : 10 * 1000;
|
|
|
|
if (!isNaN(process.env.TIMEOUT))
|
|
|
|
timeout = parseInt(process.env.TIMEOUT, 10);
|
2019-07-17 17:32:37 +00:00
|
|
|
const testRunner = new TestRunner({
|
|
|
|
timeout,
|
|
|
|
parallel,
|
|
|
|
breakOnFailure: process.argv.indexOf('--break-on-failure') !== -1,
|
|
|
|
});
|
2019-02-02 01:04:19 +00:00
|
|
|
const {describe, fdescribe, beforeAll, afterAll, beforeEach, afterEach} = testRunner;
|
2017-11-20 23:59:07 +00:00
|
|
|
|
2018-03-16 22:33:31 +00:00
|
|
|
console.log('Testing on Node', process.version);
|
|
|
|
|
2018-05-16 21:36:34 +00:00
|
|
|
beforeAll(async state => {
|
2017-08-01 22:17:57 +00:00
|
|
|
const assetsPath = path.join(__dirname, 'assets');
|
2018-02-05 22:59:07 +00:00
|
|
|
const cachedPath = path.join(__dirname, 'assets', 'cached');
|
|
|
|
|
2017-12-12 21:34:21 +00:00
|
|
|
const port = 8907 + state.parallelIndex * 2;
|
2018-09-24 19:46:39 +00:00
|
|
|
state.server = await TestServer.create(assetsPath, port);
|
2018-02-05 22:59:07 +00:00
|
|
|
state.server.enableHTTPCache(cachedPath);
|
2018-09-04 19:39:59 +00:00
|
|
|
state.server.PORT = port;
|
2017-12-12 21:34:21 +00:00
|
|
|
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;
|
2018-09-24 19:46:39 +00:00
|
|
|
state.httpsServer = await TestServer.createHTTPS(assetsPath, httpsPort);
|
2018-02-05 22:59:07 +00:00
|
|
|
state.httpsServer.enableHTTPCache(cachedPath);
|
2018-09-04 19:39:59 +00:00
|
|
|
state.httpsServer.PORT = httpsPort;
|
2017-12-12 21:34:21 +00:00
|
|
|
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`;
|
|
|
|
});
|
2017-08-01 22:17:57 +00:00
|
|
|
|
2018-03-20 03:00:12 +00:00
|
|
|
afterAll(async({server, httpsServer}) => {
|
2017-08-01 22:17:57 +00:00
|
|
|
await Promise.all([
|
|
|
|
server.stop(),
|
|
|
|
httpsServer.stop(),
|
|
|
|
]);
|
2017-12-12 21:34:21 +00:00
|
|
|
});
|
2017-08-01 22:17:57 +00:00
|
|
|
|
2018-04-09 23:38:00 +00:00
|
|
|
beforeEach(async({server, httpsServer}) => {
|
|
|
|
server.reset();
|
|
|
|
httpsServer.reset();
|
|
|
|
});
|
|
|
|
|
2019-01-26 04:21:14 +00:00
|
|
|
const CHROMIUM_NO_COVERAGE = new Set([
|
|
|
|
'page.bringToFront',
|
|
|
|
]);
|
2018-04-09 23:38:00 +00:00
|
|
|
|
2019-02-08 21:29:13 +00:00
|
|
|
if (process.env.BROWSER === 'firefox') {
|
|
|
|
testRunner.addTestDSL('it_fails_ffox', 'skip');
|
|
|
|
testRunner.addSuiteDSL('describe_fails_ffox', 'skip');
|
|
|
|
describe('Firefox', () => {
|
|
|
|
require('./puppeteer.spec.js').addTests({
|
|
|
|
product: 'Firefox',
|
2019-02-25 20:40:17 +00:00
|
|
|
puppeteerPath: path.resolve(__dirname, '../experimental/puppeteer-firefox/'),
|
2019-02-08 21:29:13 +00:00
|
|
|
testRunner,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2019-02-06 06:32:41 +00:00
|
|
|
testRunner.addTestDSL('it_fails_ffox', 'run');
|
|
|
|
testRunner.addSuiteDSL('describe_fails_ffox', 'run');
|
2019-02-02 01:04:19 +00:00
|
|
|
describe('Chromium', () => {
|
|
|
|
require('./puppeteer.spec.js').addTests({
|
|
|
|
product: 'Chromium',
|
2019-02-25 20:40:17 +00:00
|
|
|
puppeteerPath: utils.projectRoot(),
|
2019-02-02 01:04:19 +00:00
|
|
|
testRunner,
|
|
|
|
});
|
|
|
|
if (process.env.COVERAGE)
|
|
|
|
utils.recordAPICoverage(testRunner, require('../lib/api'), CHROMIUM_NO_COVERAGE);
|
2018-04-09 23:38:00 +00:00
|
|
|
});
|
2019-02-02 01:04:19 +00:00
|
|
|
}
|
2017-12-08 00:37:22 +00:00
|
|
|
|
2018-04-09 23:38:00 +00:00
|
|
|
if (process.env.CI && testRunner.hasFocusedTestsOrSuites()) {
|
2017-12-28 23:41:57 +00:00
|
|
|
console.error('ERROR: "focused" tests/suites are prohibitted on bots. Remove any "fit"/"fdescribe" declarations.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-04-09 23:38:00 +00:00
|
|
|
|
2019-02-05 23:28:35 +00:00
|
|
|
new Reporter(testRunner, {
|
2019-02-07 21:17:29 +00:00
|
|
|
verbose: process.argv.includes('--verbose'),
|
|
|
|
summary: !process.argv.includes('--verbose'),
|
2019-02-05 23:28:35 +00:00
|
|
|
projectFolder: utils.projectRoot(),
|
|
|
|
showSlowTests: process.env.CI ? 5 : 0,
|
|
|
|
});
|
2018-04-09 23:38:00 +00:00
|
|
|
testRunner.run();
|