Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): fix multiple browsers tests #1718

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 50 additions & 45 deletions test/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
delete global.playwright;
});

testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment.
testRunner.collector().useEnvironment(playwrightEnvironment);

for (const product of products) {
const browserTypeEnvironment = new Environment('BrowserType');
browserTypeEnvironment.beforeAll(async state => {
Expand Down Expand Up @@ -145,8 +148,10 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
state.page = null;
});

testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment.
testRunner.collector().useEnvironment(playwrightEnvironment);
function loadTest(path) {
require(path);
delete require.cache[require.resolve(path)];
}

describe(product, () => {
// In addition to state, expose these two on global so that describes can access them.
Expand All @@ -164,66 +169,66 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {

// Page-level tests that are given a browser, a context and a page.
// Each test is launched in a new browser context.
require('./accessibility.spec.js');
require('./autowaiting.spec.js');
require('./click.spec.js');
require('./cookies.spec.js');
require('./dialog.spec.js');
require('./download.spec.js');
require('./elementhandle.spec.js');
require('./emulation.spec.js');
require('./evaluation.spec.js');
require('./frame.spec.js');
require('./focus.spec.js');
require('./input.spec.js');
require('./jshandle.spec.js');
require('./keyboard.spec.js');
require('./mouse.spec.js');
require('./navigation.spec.js');
require('./network.spec.js');
require('./page.spec.js');
require('./queryselector.spec.js');
require('./screenshot.spec.js');
require('./waittask.spec.js');
require('./interception.spec.js');
require('./geolocation.spec.js');
require('./workers.spec.js');
require('./capabilities.spec.js');
require('./permissions.spec.js');
loadTest('./accessibility.spec.js');
loadTest('./autowaiting.spec.js');
loadTest('./click.spec.js');
loadTest('./cookies.spec.js');
loadTest('./dialog.spec.js');
loadTest('./download.spec.js');
loadTest('./elementhandle.spec.js');
loadTest('./emulation.spec.js');
loadTest('./evaluation.spec.js');
loadTest('./frame.spec.js');
loadTest('./focus.spec.js');
loadTest('./input.spec.js');
loadTest('./jshandle.spec.js');
loadTest('./keyboard.spec.js');
loadTest('./mouse.spec.js');
loadTest('./navigation.spec.js');
loadTest('./network.spec.js');
loadTest('./page.spec.js');
loadTest('./queryselector.spec.js');
loadTest('./screenshot.spec.js');
loadTest('./waittask.spec.js');
loadTest('./interception.spec.js');
loadTest('./geolocation.spec.js');
loadTest('./workers.spec.js');
loadTest('./capabilities.spec.js');
loadTest('./permissions.spec.js');

describe.skip(product !== 'Chromium')('[Chromium]', () => {
require('./chromium/chromium.spec.js');
require('./chromium/coverage.spec.js');
require('./chromium/pdf.spec.js');
require('./chromium/session.spec.js');
loadTest('./chromium/chromium.spec.js');
loadTest('./chromium/coverage.spec.js');
loadTest('./chromium/pdf.spec.js');
loadTest('./chromium/session.spec.js');
});
});

// Browser-level tests that are given a browser.
describe('[Driver]', () => {
require('./browser.spec.js');
require('./browsercontext.spec.js');
require('./ignorehttpserrors.spec.js');
require('./popup.spec.js');
loadTest('./browser.spec.js');
loadTest('./browsercontext.spec.js');
loadTest('./ignorehttpserrors.spec.js');
loadTest('./popup.spec.js');
});
});

// Top-level tests that launch Browser themselves.
describe('[Driver]', () => {
require('./defaultbrowsercontext.spec.js');
require('./fixtures.spec.js');
require('./launcher.spec.js');
require('./headful.spec.js');
require('./multiclient.spec.js');
loadTest('./defaultbrowsercontext.spec.js');
loadTest('./fixtures.spec.js');
loadTest('./launcher.spec.js');
loadTest('./headful.spec.js');
loadTest('./multiclient.spec.js');
});

describe.skip(product !== 'Chromium')('[Chromium]', () => {
require('./chromium/launcher.spec.js');
require('./chromium/oopif.spec.js');
require('./chromium/tracing.spec.js');
loadTest('./chromium/launcher.spec.js');
loadTest('./chromium/oopif.spec.js');
loadTest('./chromium/tracing.spec.js');
});

require('./apicoverage.spec.js');
loadTest('./apicoverage.spec.js');

delete global.browserType;
delete global.playwright;
Expand Down
18 changes: 9 additions & 9 deletions utils/testrunner/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class TestWorker {
}

async _runHook(testRun, hook, fullName, passTestRun = false) {
await this._willStartHook(hook, fullName);
await this._willStartHook(testRun, hook, fullName);
const timeout = this._testRunner._hookTimeout;
const { promise, terminate } = runUserCallback(hook.body, timeout, passTestRun ? [this._state, testRun] : [this._state]);
this._runningHookTerminate = terminate;
Expand All @@ -289,13 +289,13 @@ class TestWorker {
await this._testRunner._sourceMapSupport.rewriteStackTraceWithSourceMaps(error);
message = `${hook.location.toDetailedString()} - FAILED while running "${hook.name}" in suite "${fullName}": `;
}
await this._didFailHook(hook, fullName, message, error);
await this._didFailHook(testRun, hook, fullName, message, error);
if (testRun)
testRun._error = error;
return false;
}

await this._didCompleteHook(hook, fullName);
await this._didCompleteHook(testRun, hook, fullName);
return true;
}

Expand All @@ -319,19 +319,19 @@ class TestWorker {
debug('testrunner:test')(`[${this._workerId}] ${testRun._result.toUpperCase()} "${testRun.test().fullName()}" (${testRun.test().location()})`);
}

async _willStartHook(hook, fullName) {
debug('testrunner:hook')(`[${this._workerId}] "${hook.name}" started for "${fullName}" (${hook.location})`);
async _willStartHook(testRun, hook, fullName) {
debug('testrunner:hook')(`[${this._workerId}] "${fullName}.${hook.name}" started for "${testRun ? testRun.test().fullName() : ''}" (${hook.location})`);
}

async _didFailHook(hook, fullName, message, error) {
debug('testrunner:hook')(`[${this._workerId}] "${hook.name}" FAILED for "${fullName}" (${hook.location})`);
async _didFailHook(testRun, hook, fullName, message, error) {
debug('testrunner:hook')(`[${this._workerId}] "${fullName}.${hook.name}" FAILED for "${testRun ? testRun.test().fullName() : ''}" (${hook.location})`);
if (message)
this._testRunner._result.addError(message, error, this);
this._testRunner._result.setResult(TestResult.Crashed, message);
}

async _didCompleteHook(hook, fullName) {
debug('testrunner:hook')(`[${this._workerId}] "${hook.name}" OK for "${fullName}" (${hook.location})`);
async _didCompleteHook(testRun, hook, fullName) {
debug('testrunner:hook')(`[${this._workerId}] "${fullName}.${hook.name}" OK for "${testRun ? testRun.test().fullName() : ''}" (${hook.location})`);
}

async shutdown() {
Expand Down