@@ -29,6 +29,7 @@ export { program } from 'playwright-core/lib/cli/program';
2929import { prepareErrorStack } from './reporters/base' ;
3030import { showHTMLReport } from './reporters/html' ;
3131import { createMergedReport } from './reporters/merge' ;
32+ import { filterProjects } from './runner/projectUtils' ;
3233import { Runner } from './runner/runner' ;
3334import * as testServer from './runner/testServer' ;
3435import { 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' ) ;
0 commit comments