fix(test runner): make sure worker cleans up if last test was skipped (#15552)

This commit is contained in:
Dmitry Gozman 2022-07-11 21:33:56 -07:00 committed by GitHub
parent e76d9b3b28
commit 64353c4b96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View file

@ -286,7 +286,9 @@ export class WorkerRunner extends EventEmitter {
setCurrentTestInfo(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';
this.emit('testEnd', buildTestEndPayload(testInfo));
return;
@ -300,9 +302,11 @@ export class WorkerRunner extends EventEmitter {
let shouldRunAfterEachHooks = false;
await testInfo._runWithTimeout(async () => {
if (this._isStopped) {
// Getting here means that worker is requested to stop, but was not able to
// run full cleanup yet. Skip the test, but run the cleanup.
if (this._isStopped || isSkipped) {
// Two reasons to get here:
// - 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';
didFailBeforeAllForSuite = undefined;
return;

View file

@ -783,3 +783,33 @@ test('beforeAll failure should only prevent tests that are affected', async ({ r
'%%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');
});