mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test runner): apply --last-failed after sharding (#34166)
This commit is contained in:
parent
cab2bc4e2a
commit
cd32d1b08c
@ -56,6 +56,7 @@ export class FullConfigInternal {
|
|||||||
cliFailOnFlakyTests?: boolean;
|
cliFailOnFlakyTests?: boolean;
|
||||||
cliLastFailed?: boolean;
|
cliLastFailed?: boolean;
|
||||||
testIdMatcher?: Matcher;
|
testIdMatcher?: Matcher;
|
||||||
|
lastFailedTestIdMatcher?: Matcher;
|
||||||
defineConfigWasUsed = false;
|
defineConfigWasUsed = false;
|
||||||
|
|
||||||
globalSetups: string[] = [];
|
globalSetups: string[] = [];
|
||||||
|
|||||||
@ -43,7 +43,7 @@ export class LastRunReporter implements ReporterV2 {
|
|||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
const lastRunInfo = JSON.parse(await fs.promises.readFile(this._lastRunFile, 'utf8')) as LastRunInfo;
|
const lastRunInfo = JSON.parse(await fs.promises.readFile(this._lastRunFile, 'utf8')) as LastRunInfo;
|
||||||
this._config.testIdMatcher = id => lastRunInfo.failedTests.includes(id);
|
this._config.lastFailedTestIdMatcher = id => lastRunInfo.failedTests.includes(id);
|
||||||
} catch {
|
} catch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -194,6 +194,10 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho
|
|||||||
filterTestsRemoveEmptySuites(rootSuite, test => testsInThisShard.has(test));
|
filterTestsRemoveEmptySuites(rootSuite, test => testsInThisShard.has(test));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Explicitly apply --last-failed filter after sharding.
|
||||||
|
if (config.lastFailedTestIdMatcher)
|
||||||
|
filterByTestIds(rootSuite, config.lastFailedTestIdMatcher);
|
||||||
|
|
||||||
// Now prepend dependency projects without filtration.
|
// Now prepend dependency projects without filtration.
|
||||||
{
|
{
|
||||||
// Filtering 'only' and sharding might have reduced the number of top-level projects.
|
// Filtering 'only' and sharding might have reduced the number of top-level projects.
|
||||||
|
|||||||
@ -841,3 +841,35 @@ test('should run last failed tests', async ({ runInlineTest }) => {
|
|||||||
expect(result2.passed).toBe(0);
|
expect(result2.passed).toBe(0);
|
||||||
expect(result2.failed).toBe(1);
|
expect(result2.failed).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should run last failed tests in a shard', async ({ runInlineTest }) => {
|
||||||
|
const workspace = {
|
||||||
|
'a.spec.js': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('pass-a', async () => {});
|
||||||
|
test('fail-a', async () => {
|
||||||
|
expect(1).toBe(2);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
'b.spec.js': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
test('pass-b', async () => {});
|
||||||
|
test('fail-b', async () => {
|
||||||
|
expect(1).toBe(2);
|
||||||
|
});
|
||||||
|
`,
|
||||||
|
};
|
||||||
|
const result1 = await runInlineTest(workspace, { shard: '2/2' });
|
||||||
|
expect(result1.exitCode).toBe(1);
|
||||||
|
expect(result1.passed).toBe(1);
|
||||||
|
expect(result1.failed).toBe(1);
|
||||||
|
expect(result1.output).toContain('b.spec.js:3:11 › pass-b');
|
||||||
|
expect(result1.output).toContain('b.spec.js:4:11 › fail-b');
|
||||||
|
|
||||||
|
const result2 = await runInlineTest(workspace, { shard: '2/2' }, {}, { additionalArgs: ['--last-failed'] });
|
||||||
|
expect(result2.exitCode).toBe(1);
|
||||||
|
expect(result2.passed).toBe(0);
|
||||||
|
expect(result2.failed).toBe(1);
|
||||||
|
expect(result2.output).not.toContain('b.spec.js:3:11 › pass-b');
|
||||||
|
expect(result2.output).toContain('b.spec.js:4:11 › fail-b');
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user