diff --git a/packages/playwright/src/runner/loadUtils.ts b/packages/playwright/src/runner/loadUtils.ts index a2cce3b386459..bca87af72e3ae 100644 --- a/packages/playwright/src/runner/loadUtils.ts +++ b/packages/playwright/src/runner/loadUtils.ts @@ -188,9 +188,6 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho suiteUtils.filterTestsRemoveEmptySuites(rootSuite, test => testsInThisShard.has(test)); } - if (testRun.postShardTestFilters.length) - suiteUtils.filterTestsRemoveEmptySuites(rootSuite, test => testRun.postShardTestFilters.every(filter => filter(test))); - const topLevelProjects = []; // Now prepend dependency projects without filtration. { @@ -207,6 +204,9 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho } } + if (testRun.postShardTestFilters.length) + suiteUtils.filterTestsRemoveEmptySuites(rootSuite, test => testRun.postShardTestFilters.every(filter => filter(test))); + testRun.rootSuite = rootSuite; testRun.topLevelProjects = topLevelProjects; } diff --git a/tests/playwright-test/runner.spec.ts b/tests/playwright-test/runner.spec.ts index ea0ed5129121d..a9cdb36965129 100644 --- a/tests/playwright-test/runner.spec.ts +++ b/tests/playwright-test/runner.spec.ts @@ -954,3 +954,42 @@ test('should run last failed tests in a shard with --last-failed-file', async ({ expect(result2.output).not.toContain('b.spec.js:3:11 › pass-b'); expect(result2.output).toContain('b.spec.js:4:11 › fail-b'); }); + +test('should apply --last-failed to dependency projects as well', async ({ runInlineTest }) => { + const workspace = { + 'a.spec.ts': ` + import { test, expect } from '@playwright/test'; + test('pass-a', async () => {}); + test('fail-a', async () => { + expect(1).toBe(2); + }); + `, + 'b.spec.ts': ` + import { test, expect } from '@playwright/test'; + test.beforeAll(async () => {}); + test('pass-b', async () => {}); + test('fail-b', async () => { + expect(1).toBe(2); + }); + `, + 'playwright.config.ts': ` + import { defineConfig } from '@playwright/test'; + export default defineConfig({ + projects: [ + { name: 'setup', testMatch: /a\\.spec\\.ts/ }, + { name: 'main', testMatch: /b\\.spec\\.ts/, dependencies: ['setup'] }, + ], + }); + `, + }; + + const result1 = await runInlineTest(workspace); + expect(result1.exitCode).toBe(1); + expect(result1.passed).toBe(1); + expect(result1.failed).toBe(2); + + const result2 = await runInlineTest(workspace, {}, {}, { additionalArgs: ['--last-failed'] }); + expect(result2.exitCode).toBe(1); + expect(result2.passed).toBe(0); + expect(result2.failed).toBe(2); +});