fix(tests): accomodate isplaywrightready (#1746)
This commit is contained in:
parent
cd2ecb2212
commit
bf656ea318
83
test/test.js
83
test/test.js
|
|
@ -20,26 +20,27 @@ const readline = require('readline');
|
|||
const TestRunner = require('../utils/testrunner/');
|
||||
const {Environment} = require('../utils/testrunner/Test');
|
||||
|
||||
let parallel = 1;
|
||||
if (process.env.PW_PARALLEL_TESTS)
|
||||
function collect(browserNames) {
|
||||
let parallel = 1;
|
||||
if (process.env.PW_PARALLEL_TESTS)
|
||||
parallel = parseInt(process.env.PW_PARALLEL_TESTS.trim(), 10);
|
||||
const parallelArgIndex = process.argv.indexOf('-j');
|
||||
if (parallelArgIndex !== -1)
|
||||
const parallelArgIndex = process.argv.indexOf('-j');
|
||||
if (parallelArgIndex !== -1)
|
||||
parallel = parseInt(process.argv[parallelArgIndex + 1], 10);
|
||||
require('events').defaultMaxListeners *= parallel;
|
||||
require('events').defaultMaxListeners *= parallel;
|
||||
|
||||
let timeout = process.env.CI ? 30 * 1000 : 10 * 1000;
|
||||
if (!isNaN(process.env.TIMEOUT))
|
||||
let timeout = process.env.CI ? 30 * 1000 : 10 * 1000;
|
||||
if (!isNaN(process.env.TIMEOUT))
|
||||
timeout = parseInt(process.env.TIMEOUT * 1000, 10);
|
||||
const MAJOR_NODEJS_VERSION = parseInt(process.version.substring(1).split('.')[0], 10);
|
||||
if (MAJOR_NODEJS_VERSION >= 8 && require('inspector').url()) {
|
||||
const MAJOR_NODEJS_VERSION = parseInt(process.version.substring(1).split('.')[0], 10);
|
||||
if (MAJOR_NODEJS_VERSION >= 8 && require('inspector').url()) {
|
||||
console.log('Detected inspector - disabling timeout to be debugger-friendly');
|
||||
timeout = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const config = require('./test.config');
|
||||
const config = require('./test.config');
|
||||
|
||||
const testRunner = new TestRunner({
|
||||
const testRunner = new TestRunner({
|
||||
timeout,
|
||||
totalTimeout: process.env.CI ? 15 * 60 * 1000 : 0,
|
||||
parallel,
|
||||
|
|
@ -48,38 +49,32 @@ const testRunner = new TestRunner({
|
|||
summary: !process.argv.includes('--verbose'),
|
||||
showSlowTests: process.env.CI ? 5 : 0,
|
||||
showMarkedAsFailingTests: 10,
|
||||
});
|
||||
if (config.setupTestRunner)
|
||||
});
|
||||
if (config.setupTestRunner)
|
||||
config.setupTestRunner(testRunner);
|
||||
|
||||
console.log('Testing on Node', process.version);
|
||||
|
||||
const browserNames = ['chromium', 'firefox', 'webkit'].filter(name => {
|
||||
return process.env.BROWSER === name || process.env.BROWSER === 'all';
|
||||
});
|
||||
|
||||
for (const [key, value] of Object.entries(testRunner.api()))
|
||||
for (const [key, value] of Object.entries(testRunner.api()))
|
||||
global[key] = value;
|
||||
|
||||
// TODO: this should be a preinstalled playwright by default.
|
||||
const playwrightPath = config.playwrightPath;
|
||||
const playwright = require(playwrightPath);
|
||||
// TODO: this should be a preinstalled playwright by default.
|
||||
const playwrightPath = config.playwrightPath;
|
||||
const playwright = require(playwrightPath);
|
||||
|
||||
const playwrightEnvironment = new Environment('Playwright');
|
||||
playwrightEnvironment.beforeAll(async state => {
|
||||
const playwrightEnvironment = new Environment('Playwright');
|
||||
playwrightEnvironment.beforeAll(async state => {
|
||||
state.playwright = playwright;
|
||||
global.playwright = playwright;
|
||||
});
|
||||
playwrightEnvironment.afterAll(async state => {
|
||||
});
|
||||
playwrightEnvironment.afterAll(async state => {
|
||||
delete state.playwright;
|
||||
delete global.playwright;
|
||||
});
|
||||
});
|
||||
|
||||
testRunner.collector().useEnvironment(playwrightEnvironment);
|
||||
for (const e of config.globalEnvironments || [])
|
||||
testRunner.collector().useEnvironment(playwrightEnvironment);
|
||||
for (const e of config.globalEnvironments || [])
|
||||
testRunner.collector().useEnvironment(e);
|
||||
|
||||
for (const browserName of browserNames) {
|
||||
for (const browserName of browserNames) {
|
||||
const browserType = playwright[browserName];
|
||||
const browserTypeEnvironment = new Environment('BrowserType');
|
||||
browserTypeEnvironment.beforeAll(async state => {
|
||||
|
|
@ -192,17 +187,29 @@ for (const browserName of browserNames) {
|
|||
delete global.browserType;
|
||||
delete global.playwright;
|
||||
});
|
||||
}
|
||||
for (const [key, value] of Object.entries(testRunner.api())) {
|
||||
}
|
||||
for (const [key, value] of Object.entries(testRunner.api())) {
|
||||
// expect is used when running tests, while the rest of api is not.
|
||||
if (key !== 'expect')
|
||||
delete global[key];
|
||||
}
|
||||
}
|
||||
|
||||
const filterArgIndex = process.argv.indexOf('--filter');
|
||||
if (filterArgIndex !== -1) {
|
||||
const filterArgIndex = process.argv.indexOf('--filter');
|
||||
if (filterArgIndex !== -1) {
|
||||
const filter = process.argv[filterArgIndex + 1];
|
||||
testRunner.focusMatchingTests(new RegExp(filter, 'i'));
|
||||
}
|
||||
|
||||
return testRunner;
|
||||
}
|
||||
|
||||
testRunner.run().then(() => { delete global.expect; });
|
||||
module.exports = collect;
|
||||
|
||||
if (require.main === module) {
|
||||
console.log('Testing on Node', process.version);
|
||||
const browserNames = ['chromium', 'firefox', 'webkit'].filter(name => {
|
||||
return process.env.BROWSER === name || process.env.BROWSER === 'all';
|
||||
});
|
||||
const testRunner = collect(browserNames);
|
||||
testRunner.run().then(() => { delete global.expect; });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ const PROJECT_ROOT = fs.existsSync(path.join(__dirname, '..', 'package.json')) ?
|
|||
const mkdtempAsync = util.promisify(require('fs').mkdtemp);
|
||||
const removeFolderAsync = util.promisify(removeFolder);
|
||||
|
||||
let platform = os.platform();
|
||||
|
||||
const utils = module.exports = {
|
||||
/**
|
||||
* @return {string}
|
||||
|
|
@ -182,9 +184,9 @@ const utils = module.exports = {
|
|||
FFOX: browserType.name() === 'firefox',
|
||||
WEBKIT: browserType.name() === 'webkit',
|
||||
CHROMIUM: browserType.name() === 'chromium',
|
||||
MAC: os.platform() === 'darwin',
|
||||
LINUX: os.platform() === 'linux',
|
||||
WIN: os.platform() === 'win32',
|
||||
MAC: platform === 'darwin',
|
||||
LINUX: platform === 'linux',
|
||||
WIN: platform === 'win32',
|
||||
browserType,
|
||||
defaultBrowserOptions,
|
||||
playwrightPath: PROJECT_ROOT,
|
||||
|
|
@ -193,6 +195,11 @@ const utils = module.exports = {
|
|||
OUTPUT_DIR,
|
||||
};
|
||||
},
|
||||
|
||||
setPlatform(p) {
|
||||
// To support isplaywrightready.
|
||||
platform = p;
|
||||
},
|
||||
};
|
||||
|
||||
function valueFromEnv(name, defaultValue) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue