playwright/test/test.config.js
Andrey Lushnikov 1605cb453c
testrunner: make environment a simple class (#2769)
This patch:
- makes environment a simple class with optional methods `beforeEach`, `afterEach`, `beforeAll`, `afterAll`, `globalSetup` and `globalTeardown`
- removes capability to have multiple hooks of the same name inside suite
- removes default environment for test. (`dit` now adds a `TraceTestEnvironment` to the test)
- extracts all environments that we use in our tests in `//test/environments.js`

Downsides:
- we no longer know hook locations for the environments. This, however, should not be a big deal since stack traces (if any) will still point into it.
- this also regresses hook locations for suites for simplicity. We can get them back, but it shouldn't be pressing since we now have only one hook of each kind in every suite.
2020-06-30 16:51:03 -07:00

179 lines
5.2 KiB
JavaScript

/**
* Copyright 2019 Google Inc. All rights reserved.
* Modifications 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 path = require('path');
const utils = require('./utils');
const {DefaultBrowserOptionsEnvironment, ServerEnvironment, GoldenEnvironment, TraceTestEnvironment} = require('./environments.js');
const playwrightPath = path.join(__dirname, '..');
const dumpLogOnFailure = valueFromEnv('DEBUGP', false);
const defaultBrowserOptionsEnvironment = new DefaultBrowserOptionsEnvironment({
handleSIGINT: false,
slowMo: valueFromEnv('SLOW_MO', 0),
headless: !!valueFromEnv('HEADLESS', true),
}, dumpLogOnFailure, playwrightPath);
const serverEnvironment = new ServerEnvironment();
const customEnvironment = new GoldenEnvironment();
function valueFromEnv(name, defaultValue) {
if (!(name in process.env))
return defaultValue;
return JSON.parse(process.env[name]);
}
function setupTestRunner(testRunner) {
const collector = testRunner.collector();
collector.addTestModifier('skip', (t, condition) => condition && t.setSkipped(true));
collector.addSuiteModifier('skip', (s, condition) => condition && s.setSkipped(true));
collector.addTestModifier('fail', (t, condition) => condition && t.setExpectation(t.Expectations.Fail));
collector.addSuiteModifier('fail', (s, condition) => condition && s.setExpectation(s.Expectations.Fail));
collector.addTestModifier('slow', t => t.setTimeout(t.timeout() * 3));
collector.addTestAttribute('debug', t => TraceTestEnvironment.enableForTest(t));
testRunner.api().fdescribe = testRunner.api().describe.only;
testRunner.api().xdescribe = testRunner.api().describe.skip(true);
testRunner.api().fit = testRunner.api().it.only;
testRunner.api().xit = testRunner.api().it.skip(true);
testRunner.api().dit = testRunner.api().it.only.debug;
}
module.exports = {
playwrightPath,
dumpLogOnFailure: valueFromEnv('DEBUGP', false),
launchOptions: {
executablePath: {
chromium: process.env.CRPATH,
firefox: process.env.FFPATH,
webkit: process.env.WKPATH,
},
slowMo: valueFromEnv('SLOW_MO', 0),
headless: !!valueFromEnv('HEADLESS', true),
},
globalEnvironments: [defaultBrowserOptionsEnvironment, serverEnvironment],
setupTestRunner,
specs: [
{
files: [
'./accessibility.spec.js',
'./autowaiting.spec.js',
'./click.spec.js',
'./cookies.spec.js',
'./dialog.spec.js',
'./dispatchevent.spec.js',
'./download.spec.js',
'./elementhandle.spec.js',
'./emulation.spec.js',
'./evaluation.spec.js',
'./frame.spec.js',
'./focus.spec.js',
'./input.spec.js',
'./jshandle.spec.js',
'./keyboard.spec.js',
'./mouse.spec.js',
'./navigation.spec.js',
'./network.spec.js',
'./page.spec.js',
'./queryselector.spec.js',
'./screenshot.spec.js',
'./waittask.spec.js',
'./interception.spec.js',
'./geolocation.spec.js',
'./workers.spec.js',
'./capabilities.spec.js',
'./permissions.spec.js',
],
environments: [customEnvironment, 'page'],
},
{
files: [
'./chromium/chromium.spec.js',
'./chromium/coverage.spec.js',
'./chromium/pdf.spec.js',
'./chromium/session.spec.js',
],
browsers: ['chromium'],
title: '[Chromium]',
environments: [customEnvironment, 'page'],
},
{
files: [
'./browser.spec.js',
'./browsercontext.spec.js',
'./ignorehttpserrors.spec.js',
'./popup.spec.js',
'./recorder.spec.js',
],
environments: [customEnvironment, 'browser'],
},
{
files: [
'./defaultbrowsercontext.spec.js',
'./downloadsPath.spec.js',
'./fixtures.spec.js',
'./launcher.spec.js',
'./logger.spec.js',
'./headful.spec.js',
'./multiclient.spec.js',
'./proxy.spec.js',
],
environments: [customEnvironment],
},
{
files: [
'./chromium/launcher.spec.js',
'./chromium/oopif.spec.js',
'./chromium/tracing.spec.js',
],
browsers: ['chromium'],
title: '[Chromium]',
environments: [customEnvironment],
},
{
files: [
'./firefox/launcher.spec.js',
],
browsers: ['firefox'],
title: '[Firefox]',
environments: [customEnvironment],
},
{
files: [
'./electron/electron.spec.js',
],
browsers: ['chromium'],
title: '[Electron]',
environments: [customEnvironment],
},
{
files: [
'./apicoverage.spec.js',
],
environments: [],
},
],
};