Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test runner): always show all projects in selection (#32450)

Simon Knott0e3f4736cc5f
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 }) => {