fix(test runner): make sure worker cleans up if last test was skipped (#15552)
This commit is contained in:
parent
e76d9b3b28
commit
64353c4b96
|
|
@ -286,7 +286,9 @@ export class WorkerRunner extends EventEmitter {
|
||||||
setCurrentTestInfo(testInfo);
|
setCurrentTestInfo(testInfo);
|
||||||
this.emit('testBegin', buildTestBeginPayload(testInfo));
|
this.emit('testBegin', buildTestBeginPayload(testInfo));
|
||||||
|
|
||||||
if (testInfo.expectedStatus === 'skipped') {
|
const isSkipped = testInfo.expectedStatus === 'skipped';
|
||||||
|
if (isSkipped && nextTest) {
|
||||||
|
// Fast path - this test and skipped, and there are more tests that will handle cleanup.
|
||||||
testInfo.status = 'skipped';
|
testInfo.status = 'skipped';
|
||||||
this.emit('testEnd', buildTestEndPayload(testInfo));
|
this.emit('testEnd', buildTestEndPayload(testInfo));
|
||||||
return;
|
return;
|
||||||
|
|
@ -300,9 +302,11 @@ export class WorkerRunner extends EventEmitter {
|
||||||
let shouldRunAfterEachHooks = false;
|
let shouldRunAfterEachHooks = false;
|
||||||
|
|
||||||
await testInfo._runWithTimeout(async () => {
|
await testInfo._runWithTimeout(async () => {
|
||||||
if (this._isStopped) {
|
if (this._isStopped || isSkipped) {
|
||||||
// Getting here means that worker is requested to stop, but was not able to
|
// Two reasons to get here:
|
||||||
// run full cleanup yet. Skip the test, but run the cleanup.
|
// - Last test is skipped, so we should not run the test, but run the cleanup.
|
||||||
|
// - Worker is requested to stop, but was not able to run full cleanup yet.
|
||||||
|
// We should skip the test, but run the cleanup.
|
||||||
testInfo.status = 'skipped';
|
testInfo.status = 'skipped';
|
||||||
didFailBeforeAllForSuite = undefined;
|
didFailBeforeAllForSuite = undefined;
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -783,3 +783,33 @@ test('beforeAll failure should only prevent tests that are affected', async ({ r
|
||||||
'%%test3',
|
'%%test3',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('afterAll should run if last test was skipped', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.afterAll(() => console.log('after-all'));
|
||||||
|
test('test1', () => {});
|
||||||
|
test.skip('test2', () => {});
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.skipped).toBe(1);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.output).toContain('after-all');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('afterAll should run if last test was skipped 2', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'a.test.js': `
|
||||||
|
const { test } = pwt;
|
||||||
|
test.afterAll(() => console.log('after-all'));
|
||||||
|
test('test1', () => {});
|
||||||
|
test('test2', () => { test.skip(); });
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.skipped).toBe(1);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
expect(result.output).toContain('after-all');
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue