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,