From 0e3f4736cc5f31823174e4b57c9c30ac2320d168 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 6 Sep 2024 11:35:20 +0200 Subject: [PATCH] fix(test runner): always show all projects in selection (#32450) Follow-up to https://github.com/microsoft/playwright/pull/32156#discussion_r1741628770, alternative solution to https://github.com/microsoft/playwright/pull/32425. Ensures we always show all projects in the watch mode project selector by performing the initial `listTests` without any filters, and using its result for the project selector. --- packages/playwright/src/runner/watchMode.ts | 6 ++++-- tests/playwright-test/watch.spec.ts | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/playwright/src/runner/watchMode.ts b/packages/playwright/src/runner/watchMode.ts index 924449adce..ba2c5a34e7 100644 --- a/packages/playwright/src/runner/watchMode.ts +++ b/packages/playwright/src/runner/watchMode.ts @@ -125,9 +125,11 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp await testServerConnection.initialize({ interceptStdio: false, watchTestDirs: true }); await testServerConnection.runGlobalSetup({}); - const { report } = await testServerConnection.listTests({ locations: options.files, projects: options.projects, grep: options.grep }); + const { report } = await testServerConnection.listTests({}); teleSuiteUpdater.processListReport(report); + const projectNames = teleSuiteUpdater.rootSuite!.suites.map(s => s.title); + let lastRun: { type: 'changed' | 'regular' | 'failed', failedTestIds?: string[], dirtyTestIds?: string[] } = { type: 'regular' }; let result: FullResult['status'] = 'passed'; @@ -167,7 +169,7 @@ export async function runWatchModeLoop(configLocation: ConfigLocation, initialOp type: 'multiselect', name: 'selectedProjects', message: 'Select projects', - choices: teleSuiteUpdater.rootSuite!.suites.map(s => s.title), + choices: projectNames, }).catch(() => ({ selectedProjects: null })); if (!selectedProjects) continue; diff --git a/tests/playwright-test/watch.spec.ts b/tests/playwright-test/watch.spec.ts index 0dba9dd861..f4d1fd72ce 100644 --- a/tests/playwright-test/watch.spec.ts +++ b/tests/playwright-test/watch.spec.ts @@ -282,8 +282,8 @@ test('should respect file filter P', async ({ runWatchTest }) => { await testProcess.waitForOutput('Waiting for file changes.'); }); -test('should respect project filter C', async ({ runWatchTest }) => { - const testProcess = await runWatchTest({ +test('should respect project filter C', async ({ runWatchTest, writeFiles }) => { + const files = { 'playwright.config.ts': ` import { defineConfig } from '@playwright/test'; export default defineConfig({ projects: [{name: 'foo'}, {name: 'bar'}] }); @@ -292,9 +292,9 @@ test('should respect project filter C', async ({ runWatchTest }) => { import { test, expect } from '@playwright/test'; test('passes', () => {}); `, - }); + }; + const testProcess = await runWatchTest(files, { project: 'foo' }); await testProcess.waitForOutput('[foo] › a.test.ts:3:11 › passes'); - await testProcess.waitForOutput('[bar] › a.test.ts:3:11 › passes'); await testProcess.waitForOutput('Waiting for file changes.'); testProcess.clearOutput(); testProcess.write('c'); @@ -306,6 +306,16 @@ test('should respect project filter C', async ({ runWatchTest }) => { await testProcess.waitForOutput('npx playwright test --project foo #1'); await testProcess.waitForOutput('[foo] › a.test.ts:3:11 › passes'); expect(testProcess.output).not.toContain('[bar] › a.test.ts:3:11 › passes'); + + testProcess.clearOutput(); + + await writeFiles(files); // file change triggers listTests with project filter + await testProcess.waitForOutput('[foo] › a.test.ts:3:11 › passes'); + + testProcess.write('c'); + await testProcess.waitForOutput('Select projects'); + await testProcess.waitForOutput('foo'); + await testProcess.waitForOutput('bar'); // second selection should still show all }); test('should respect file filter P and split files', async ({ runWatchTest }) => {