diff --git a/packages/playwright-test/src/runner/loadUtils.ts b/packages/playwright-test/src/runner/loadUtils.ts index 62ef1877e0..a940b89d71 100644 --- a/packages/playwright-test/src/runner/loadUtils.ts +++ b/packages/playwright-test/src/runner/loadUtils.ts @@ -144,6 +144,18 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho } } + if (shouldFilterOnly) { + // Create a fake root to execute the exclusive semantics across the projects. + const filteredRoot = new Suite('', 'root'); + for (const filteredProjectSuite of filteredProjectSuites.values()) + filteredRoot._addSuite(filteredProjectSuite); + filterOnly(filteredRoot); + for (const [project, filteredProjectSuite] of filteredProjectSuites) { + if (!filteredRoot.suites.includes(filteredProjectSuite)) + filteredProjectSuites.delete(project); + } + } + // Add post-filtered top-level projects to the root suite for sharding and 'only' processing. const projectClosure = buildProjectsClosure([...filteredProjectSuites.keys()], project => filteredProjectSuites.get(project)!._hasTests()); for (const [project, type] of projectClosure) { @@ -162,10 +174,6 @@ export async function createRootSuite(testRun: TestRun, errors: TestError[], sho } } - // Filter only for top-level projects. - if (shouldFilterOnly) - filterOnly(rootSuite); - // Shard only the top-level projects. if (config.config.shard) { // Create test groups for top-level projects. diff --git a/tests/playwright-test/deps.spec.ts b/tests/playwright-test/deps.spec.ts index ece6d476eb..4e97cb4d09 100644 --- a/tests/playwright-test/deps.spec.ts +++ b/tests/playwright-test/deps.spec.ts @@ -210,7 +210,7 @@ test('should not filter dependency by file name', async ({ runInlineTest }) => { expect(result.output).toContain('1) [A] › one.spec.ts:3:11 › fails'); }); -test('should not filter dependency by only', async ({ runInlineTest }) => { +test('should filter dependency by only', async ({ runInlineTest }) => { const result = await runInlineTest({ 'playwright.config.ts': ` module.exports = { projects: [ @@ -235,7 +235,7 @@ test('should not filter dependency by only', async ({ runInlineTest }) => { `, }); expect(result.exitCode).toBe(0); - expect(result.outputLines).toEqual(['setup in setup', 'setup 2 in setup', 'test in browser']); + expect(result.outputLines).toEqual(['setup 2 in setup']); }); test('should filter dependency by only when running explicitly', async ({ runInlineTest }) => {