From b1b21bdac5c39e11b3293a28916fb4f62e70832d Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 29 Nov 2022 16:02:11 -0800 Subject: [PATCH] fix(shards): zero-sized shard should not include all tests (#19148) Fixes #19073. --- packages/playwright-test/src/runner.ts | 10 +++++++++- tests/playwright-test/shard.spec.ts | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.ts index 8ceb9a0cd9..6bd73a9709 100644 --- a/packages/playwright-test/src/runner.ts +++ b/packages/playwright-test/src/runner.ts @@ -431,7 +431,15 @@ export class Runner { projectSetupGroups.length = 0; projectSetupGroups.push(...shardSetupGroups); - filterSuiteWithOnlySemantics(rootSuite, () => false, test => shardTests.has(test)); + if (!shardTests.size) { + // Filtering with "only semantics" does not work when we have zero tests - it leaves all the tests. + // We need an empty suite in this case. + rootSuite._entries = []; + rootSuite.suites = []; + rootSuite.tests = []; + } else { + filterSuiteWithOnlySemantics(rootSuite, () => false, test => shardTests.has(test)); + } } private async _run(options: RunOptions): Promise { diff --git a/tests/playwright-test/shard.spec.ts b/tests/playwright-test/shard.spec.ts index fc84d8402c..8eb018e8bd 100644 --- a/tests/playwright-test/shard.spec.ts +++ b/tests/playwright-test/shard.spec.ts @@ -63,6 +63,15 @@ test('should respect shard=2/2', async ({ runInlineTest }) => { expect(result.output).toContain('test5-done'); }); +test('should not produce skipped tests for zero-sized shards', async ({ runInlineTest }) => { + const result = await runInlineTest(tests, { shard: '10/10' }); + expect(result.exitCode).toBe(0); + expect(result.passed).toBe(0); + expect(result.failed).toBe(0); + expect(result.skipped).toBe(0); + expect(result.output).not.toContain('-done'); +}); + test('should respect shard=1/2 in config', async ({ runInlineTest }) => { const result = await runInlineTest({ ...tests,