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:
parent
e9378ba5fc
commit
e8fb5a6337
|
|
@ -379,6 +379,7 @@ export class WorkerRunner extends EventEmitter {
|
||||||
if (testInfo.status === 'timedOut') {
|
if (testInfo.status === 'timedOut') {
|
||||||
// A timed-out test gets a full additional timeout to run after hooks.
|
// A timed-out test gets a full additional timeout to run after hooks.
|
||||||
afterHooksSlot = { timeout: this._project.timeout, elapsed: 0 };
|
afterHooksSlot = { timeout: this._project.timeout, elapsed: 0 };
|
||||||
|
testInfo._timeoutManager.setCurrentRunnable({ type: 'afterEach', slot: afterHooksSlot });
|
||||||
}
|
}
|
||||||
await testInfo._runWithTimeout(async () => {
|
await testInfo._runWithTimeout(async () => {
|
||||||
// Note: do not wrap all teardown steps together, because failure in any of them
|
// Note: do not wrap all teardown steps together, because failure in any of them
|
||||||
|
|
|
||||||
|
|
@ -306,3 +306,37 @@ test('fixture time in beforeEach hook should affect test', async ({ runInlineTes
|
||||||
expect(result.failed).toBe(1);
|
expect(result.failed).toBe(1);
|
||||||
expect(result.output).toContain('Timeout of 1000ms exceeded');
|
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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue