fix(shards): zero-sized shard should not include all tests (#19148)

Fixes #19073.
This commit is contained in:
Dmitry Gozman 2022-11-29 16:02:11 -08:00 committed by GitHub
parent b7a49fb371
commit b1b21bdac5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -431,8 +431,16 @@ export class Runner {
projectSetupGroups.length = 0;
projectSetupGroups.push(...shardSetupGroups);
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<FullResult> {
const config = this._loader.fullConfig();

View file

@ -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,