From 95a1230209c4c443ead2944b079ae83541f344b3 Mon Sep 17 00:00:00 2001 From: Adam Gastineau Date: Fri, 7 Feb 2025 11:27:12 -0800 Subject: [PATCH] fix(runner): display no projects error across all `test` modes --- packages/playwright/src/program.ts | 32 ++++++++++++++++------------ tests/playwright-test/config.spec.ts | 19 +++++++++++++++++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.ts index c6278dc0ad..3aa9edcf52 100644 --- a/packages/playwright/src/program.ts +++ b/packages/playwright/src/program.ts @@ -35,6 +35,7 @@ import type { ReporterDescription } from '../types/test'; import { prepareErrorStack } from './reporters/base'; import * as testServer from './runner/testServer'; import { runWatchModeLoop } from './runner/watchMode'; +import { filterProjects } from './runner/projectUtils'; function addTestCommand(program: Command) { const command = program.command('test [test-filter...]'); @@ -157,6 +158,23 @@ async function runTests(args: string[], opts: { [key: string]: any }) { await startProfiling(); const cliOverrides = overridesFromOptions(opts); + const config = await loadConfigFromFileRestartIfNeeded(opts.config, cliOverrides, opts.deps === false); + if (!config) + return; + + config.cliArgs = args; + config.cliGrep = opts.grep as string | undefined; + config.cliOnlyChanged = opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged; + config.cliGrepInvert = opts.grepInvert as string | undefined; + config.cliListOnly = !!opts.list; + config.cliProjectFilter = opts.project || undefined; + config.cliPassWithNoTests = !!opts.passWithNoTests; + config.cliFailOnFlakyTests = !!opts.failOnFlakyTests; + config.cliLastFailed = !!opts.lastFailed; + + // Evaluate project filters against config before starting execution. This enables a consistent error message across run modes + filterProjects(config.projects, config.cliProjectFilter); + if (opts.ui || opts.uiHost || opts.uiPort) { if (opts.onlyChanged) 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.`); @@ -198,20 +216,6 @@ async function runTests(args: string[], opts: { [key: string]: any }) { return; } - const config = await loadConfigFromFileRestartIfNeeded(opts.config, cliOverrides, opts.deps === false); - if (!config) - return; - - config.cliArgs = args; - config.cliGrep = opts.grep as string | undefined; - config.cliOnlyChanged = opts.onlyChanged === true ? 'HEAD' : opts.onlyChanged; - config.cliGrepInvert = opts.grepInvert as string | undefined; - config.cliListOnly = !!opts.list; - config.cliProjectFilter = opts.project || undefined; - config.cliPassWithNoTests = !!opts.passWithNoTests; - config.cliFailOnFlakyTests = !!opts.failOnFlakyTests; - config.cliLastFailed = !!opts.lastFailed; - const runner = new Runner(config); const status = await runner.runAllTests(); await stopProfiling('runner'); diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.ts index 7870d74706..cadce8d02a 100644 --- a/tests/playwright-test/config.spec.ts +++ b/tests/playwright-test/config.spec.ts @@ -327,6 +327,25 @@ test('should print nice error when project is unknown', async ({ runInlineTest } expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"'); }); +test('should print nice error when project is unknown and launching UI mode', async ({ runInlineTest }) => { + // Prevent UI mode from opening and the test never finishing + setTimeout(() => expect(false).toBeTruthy(), 5000); + const { output, exitCode } = await runInlineTest({ + 'playwright.config.ts': ` + module.exports = { projects: [ + { name: 'suite1' }, + { name: 'suite2' }, + ] }; + `, + 'a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('pass', async ({}, testInfo) => {}); + ` + }, { project: 'suite3', ui: true }); + expect(exitCode).toBe(1); + expect(output).toContain('Project(s) "suite3" not found. Available projects: "suite1", "suite2"'); +}); + test('should filter by project list, case-insensitive', async ({ runInlineTest }) => { const { passed, failed, outputLines, skipped } = await runInlineTest({ 'playwright.config.ts': `