fix(test runner): ensure that hooks run before fixtures teardown after timeout (#14035)

We had common cleanup exiting early after timeout, because we did not
reset the time slot.
This commit is contained in:
Dmitry Gozman 2022-05-09 20:38:20 +01:00 committed by GitHub
parent e9378ba5fc
commit e8fb5a6337
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -379,6 +379,7 @@ export class WorkerRunner extends EventEmitter {
if (testInfo.status === 'timedOut') {
// A timed-out test gets a full additional timeout to run after hooks.
afterHooksSlot = { timeout: this._project.timeout, elapsed: 0 };
testInfo._timeoutManager.setCurrentRunnable({ type: 'afterEach', slot: afterHooksSlot });
}
await testInfo._runWithTimeout(async () => {
// Note: do not wrap all teardown steps together, because failure in any of them

View file

@ -306,3 +306,37 @@ test('fixture time in beforeEach hook should affect test', async ({ runInlineTes
expect(result.failed).toBe(1);
expect(result.output).toContain('Timeout of 1000ms exceeded');
});
test('test timeout should still run hooks before fixtures teardown', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
const test = pwt.test.extend({
auto: [async ({}, use) => {
console.log('\\n%%before-auto');
await use('hey');
console.log('\\n%%after-auto');
}, { auto: true }]
});
test.afterAll(async () => {
console.log('\\n%%afterAll-1');
await new Promise(f => setTimeout(f, 500));
console.log('\\n%%afterAll-2');
});
test('test fail', async ({}) => {
test.setTimeout(100);
console.log('\\n%%test');
await new Promise(f => setTimeout(f, 800));
});
`
});
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('Timeout of 100ms exceeded');
expect(result.output.split('\n').filter(line => line.startsWith('%%'))).toEqual([
'%%before-auto',
'%%test',
'%%afterAll-1',
'%%afterAll-2',
'%%after-auto',
]);
});