Skip to content

Commit aeed1f5

Browse files
authored
fix(runner): display no projects error across all test modes (#34676)
1 parent 71c7f46 commit aeed1f5

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

packages/playwright/src/program.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export { program } from 'playwright-core/lib/cli/program';
2929
import { prepareErrorStack } from './reporters/base';
3030
import { showHTMLReport } from './reporters/html';
3131
import { createMergedReport } from './reporters/merge';
32+
import { filterProjects } from './runner/projectUtils';
3233
import { Runner } from './runner/runner';
3334
import * as testServer from './runner/testServer';
3435
import { runWatchModeLoop } from './runner/watchMode';
@@ -161,6 +162,23 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
161162
await startProfiling();
162163
const cliOverrides = overridesFromOptions(opts);
163164

165+
const config = await loadConfigFromFileRestartIfNeeded(opts.config, cliOverrides, opts.deps === false);
166+
if (!config)
167+
return;
168+
169+
config.cliArgs = args;
170+
config.cliGrep = opts.grep as string | undefined;
171+
config.cliOnlyChanged = opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged;
172+
config.cliGrepInvert = opts.grepInvert as string | undefined;
173+
config.cliListOnly = !!opts.list;
174+
config.cliProjectFilter = opts.project || undefined;
175+
config.cliPassWithNoTests = !!opts.passWithNoTests;
176+
config.cliFailOnFlakyTests = !!opts.failOnFlakyTests;
177+
config.cliLastFailed = !!opts.lastFailed;
178+
179+
// Evaluate project filters against config before starting execution. This enables a consistent error message across run modes
180+
filterProjects(config.projects, config.cliProjectFilter);
181+
164182
if (opts.ui || opts.uiHost || opts.uiPort) {
165183
if (opts.onlyChanged)
166184
throw new Error(`--only-changed is not supported in UI mode. If you'd like that to change, see https://github.com/microsoft/playwright/issues/15075 for more details.`);
@@ -202,20 +220,6 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
202220
return;
203221
}
204222

205-
const config = await loadConfigFromFileRestartIfNeeded(opts.config, cliOverrides, opts.deps === false);
206-
if (!config)
207-
return;
208-
209-
config.cliArgs = args;
210-
config.cliGrep = opts.grep as string | undefined;
211-
config.cliOnlyChanged = opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged;
212-
config.cliGrepInvert = opts.grepInvert as string | undefined;
213-
config.cliListOnly = !!opts.list;
214-
config.cliProjectFilter = opts.project || undefined;
215-
config.cliPassWithNoTests = !!opts.passWithNoTests;
216-
config.cliFailOnFlakyTests = !!opts.failOnFlakyTests;
217-
config.cliLastFailed = !!opts.lastFailed;
218-
219223
const runner = new Runner(config);
220224
const status = await runner.runAllTests();
221225
await stopProfiling('runner');

tests/playwright-test/config.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ test('should print nice error when project is unknown', async ({ runInlineTest }
327327
expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"');
328328
});
329329

330+
test('should print nice error when project is unknown and launching UI mode', async ({ runInlineTest }) => {
331+
// Prevent UI mode from opening and the test never finishing
332+
test.setTimeout(5000);
333+
const { output, exitCode } = await runInlineTest({
334+
'playwright.config.ts': `
335+
module.exports = { projects: [
336+
{ name: 'suite1' },
337+
{ name: 'suite2' },
338+
] };
339+
`,
340+
'a.test.ts': `
341+
import { test, expect } from '@playwright/test';
342+
test('pass', async ({}, testInfo) => {});
343+
`
344+
}, { project: 'suite3', ui: true });
345+
expect(exitCode).toBe(1);
346+
expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"');
347+
});
348+
330349
test('should filter by project list, case-insensitive', async ({ runInlineTest }) => {
331350
const { passed, failed, outputLines, skipped } = await runInlineTest({
332351
'playwright.config.ts': `

tests/playwright-test/ui-mode-test-setup.spec.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,6 @@ test('should teardown on sigint', async ({ runUITest, nodeVersion }) => {
9595
]);
9696
});
9797

98-
test('should show errors in config', async ({ runUITest }) => {
99-
const { page } = await runUITest({
100-
'playwright.config.ts': `
101-
import { defineConfig, devices } from '@playwright/test';
102-
throw new Error("URL is empty")
103-
`,
104-
});
105-
await page.getByText('playwright.config.ts').click();
106-
await expect(page.getByText('Error: URL is empty')).toBeInViewport();
107-
});
108-
10998
const testsWithSetup = {
11099
'playwright.config.ts': `
111100
import { defineConfig } from '@playwright/test';

0 commit comments

Comments
 (0)