Skip to content

Commit 2d57fff

Browse files
authored
fix(tests): fix multiple browsers tests (#1718)
- Use a server only once, not once per browser. - Avoid require cache for test files. - Improve testrunner hooks debugging.
1 parent 6723254 commit 2d57fff

File tree

2 files changed

+59
-54
lines changed

2 files changed

+59
-54
lines changed

test/playwright.spec.js

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
8787
delete global.playwright;
8888
});
8989

90+
testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment.
91+
testRunner.collector().useEnvironment(playwrightEnvironment);
92+
9093
for (const product of products) {
9194
const browserTypeEnvironment = new Environment('BrowserType');
9295
browserTypeEnvironment.beforeAll(async state => {
@@ -145,8 +148,10 @@ module.exports.addPlaywrightTests = ({testRunner, products}) => {
145148
state.page = null;
146149
});
147150

148-
testRunner.collector().useEnvironment(serverEnvironment); // Custom global environment.
149-
testRunner.collector().useEnvironment(playwrightEnvironment);
151+
function loadTest(path) {
152+
require(path);
153+
delete require.cache[require.resolve(path)];
154+
}
150155

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

165170
// Page-level tests that are given a browser, a context and a page.
166171
// Each test is launched in a new browser context.
167-
require('./accessibility.spec.js');
168-
require('./autowaiting.spec.js');
169-
require('./click.spec.js');
170-
require('./cookies.spec.js');
171-
require('./dialog.spec.js');
172-
require('./download.spec.js');
173-
require('./elementhandle.spec.js');
174-
require('./emulation.spec.js');
175-
require('./evaluation.spec.js');
176-
require('./frame.spec.js');
177-
require('./focus.spec.js');
178-
require('./input.spec.js');
179-
require('./jshandle.spec.js');
180-
require('./keyboard.spec.js');
181-
require('./mouse.spec.js');
182-
require('./navigation.spec.js');
183-
require('./network.spec.js');
184-
require('./page.spec.js');
185-
require('./queryselector.spec.js');
186-
require('./screenshot.spec.js');
187-
require('./waittask.spec.js');
188-
require('./interception.spec.js');
189-
require('./geolocation.spec.js');
190-
require('./workers.spec.js');
191-
require('./capabilities.spec.js');
192-
require('./permissions.spec.js');
172+
loadTest('./accessibility.spec.js');
173+
loadTest('./autowaiting.spec.js');
174+
loadTest('./click.spec.js');
175+
loadTest('./cookies.spec.js');
176+
loadTest('./dialog.spec.js');
177+
loadTest('./download.spec.js');
178+
loadTest('./elementhandle.spec.js');
179+
loadTest('./emulation.spec.js');
180+
loadTest('./evaluation.spec.js');
181+
loadTest('./frame.spec.js');
182+
loadTest('./focus.spec.js');
183+
loadTest('./input.spec.js');
184+
loadTest('./jshandle.spec.js');
185+
loadTest('./keyboard.spec.js');
186+
loadTest('./mouse.spec.js');
187+
loadTest('./navigation.spec.js');
188+
loadTest('./network.spec.js');
189+
loadTest('./page.spec.js');
190+
loadTest('./queryselector.spec.js');
191+
loadTest('./screenshot.spec.js');
192+
loadTest('./waittask.spec.js');
193+
loadTest('./interception.spec.js');
194+
loadTest('./geolocation.spec.js');
195+
loadTest('./workers.spec.js');
196+
loadTest('./capabilities.spec.js');
197+
loadTest('./permissions.spec.js');
193198

194199
describe.skip(product !== 'Chromium')('[Chromium]', () => {
195-
require('./chromium/chromium.spec.js');
196-
require('./chromium/coverage.spec.js');
197-
require('./chromium/pdf.spec.js');
198-
require('./chromium/session.spec.js');
200+
loadTest('./chromium/chromium.spec.js');
201+
loadTest('./chromium/coverage.spec.js');
202+
loadTest('./chromium/pdf.spec.js');
203+
loadTest('./chromium/session.spec.js');
199204
});
200205
});
201206

202207
// Browser-level tests that are given a browser.
203208
describe('[Driver]', () => {
204-
require('./browser.spec.js');
205-
require('./browsercontext.spec.js');
206-
require('./ignorehttpserrors.spec.js');
207-
require('./popup.spec.js');
209+
loadTest('./browser.spec.js');
210+
loadTest('./browsercontext.spec.js');
211+
loadTest('./ignorehttpserrors.spec.js');
212+
loadTest('./popup.spec.js');
208213
});
209214
});
210215

211216
// Top-level tests that launch Browser themselves.
212217
describe('[Driver]', () => {
213-
require('./defaultbrowsercontext.spec.js');
214-
require('./fixtures.spec.js');
215-
require('./launcher.spec.js');
216-
require('./headful.spec.js');
217-
require('./multiclient.spec.js');
218+
loadTest('./defaultbrowsercontext.spec.js');
219+
loadTest('./fixtures.spec.js');
220+
loadTest('./launcher.spec.js');
221+
loadTest('./headful.spec.js');
222+
loadTest('./multiclient.spec.js');
218223
});
219224

220225
describe.skip(product !== 'Chromium')('[Chromium]', () => {
221-
require('./chromium/launcher.spec.js');
222-
require('./chromium/oopif.spec.js');
223-
require('./chromium/tracing.spec.js');
226+
loadTest('./chromium/launcher.spec.js');
227+
loadTest('./chromium/oopif.spec.js');
228+
loadTest('./chromium/tracing.spec.js');
224229
});
225230

226-
require('./apicoverage.spec.js');
231+
loadTest('./apicoverage.spec.js');
227232

228233
delete global.browserType;
229234
delete global.playwright;

utils/testrunner/TestRunner.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class TestWorker {
264264
}
265265

266266
async _runHook(testRun, hook, fullName, passTestRun = false) {
267-
await this._willStartHook(hook, fullName);
267+
await this._willStartHook(testRun, hook, fullName);
268268
const timeout = this._testRunner._hookTimeout;
269269
const { promise, terminate } = runUserCallback(hook.body, timeout, passTestRun ? [this._state, testRun] : [this._state]);
270270
this._runningHookTerminate = terminate;
@@ -289,13 +289,13 @@ class TestWorker {
289289
await this._testRunner._sourceMapSupport.rewriteStackTraceWithSourceMaps(error);
290290
message = `${hook.location.toDetailedString()} - FAILED while running "${hook.name}" in suite "${fullName}": `;
291291
}
292-
await this._didFailHook(hook, fullName, message, error);
292+
await this._didFailHook(testRun, hook, fullName, message, error);
293293
if (testRun)
294294
testRun._error = error;
295295
return false;
296296
}
297297

298-
await this._didCompleteHook(hook, fullName);
298+
await this._didCompleteHook(testRun, hook, fullName);
299299
return true;
300300
}
301301

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

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

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

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

337337
async shutdown() {

0 commit comments

Comments
 (0)