@@ -20,30 +20,39 @@ export const getTestCommand = () => new Command('test')
2020 . addOption ( watchOption )
2121 . addOption ( updateOption )
2222 . addOption ( coverageOption )
23- . argument ( '[directory]' , 'Directory to search for tests. If no directory is specified, the current working directory is used' )
24- . action ( async ( directory , { mode, ...options } ) => {
25- const fullyResolved = resolve ( directory ?? process . cwd ( ) ) ;
26- const configResult = await getTestConfiguration ( fullyResolved , ! ! options . watch ) ;
23+ . argument ( '[project]' , 'Directory that contains the vitest config file' )
24+ . argument ( '[patterns...]' , 'Test patterns to filter by.' )
25+ . action ( async ( project , patterns , { mode, ...options } ) => {
26+ const fullyResolvedProject = resolve ( project ?? process . cwd ( ) ) ;
27+ const fullyResolvedPatterns = patterns . map ( each => resolve ( process . cwd ( ) , each ) ) ;
28+
29+ const configResult = await getTestConfiguration ( fullyResolvedProject , ! ! options . watch ) ;
2730
2831 if ( configResult . severity === 'error' ) {
2932 logCommandErrorAndExit ( configResult ) ;
3033 }
3134
3235 if ( configResult . config === null ) {
33- console . log ( chalk . yellowBright ( `No tests found for in ${ fullyResolved } ` ) ) ;
36+ console . log ( chalk . yellowBright ( `No tests found for ${ fullyResolvedProject } ` ) ) ;
3437 return ;
3538 }
3639
37- await runVitest ( mode , [ fullyResolved ] , [ configResult . config ] , options ) ;
40+ await runVitest ( mode , fullyResolvedPatterns , [ configResult . config ] , options ) ;
3841 } ) ;
3942
4043export const getTestAllCommand = ( ) => new Command ( 'testall' )
4144 . description ( 'Run all tests based on the configuration of the root vitest file' )
45+ . argument ( '[patterns...]' , 'Test patterns to filter by.' )
4246 . addOption ( vitestModeOption )
4347 . addOption ( watchOption )
4448 . addOption ( updateOption )
4549 . addOption ( coverageOption )
46- . action ( async ( { mode, ...options } ) => {
50+ . action ( async ( patterns , { mode, ...options } ) => {
4751 const configs = await getAllTestConfigurations ( ! ! options . watch ) ;
48- await runVitest ( mode , undefined , configs , options ) ;
52+ if ( configs . length === 0 ) {
53+ console . log ( chalk . yellowBright ( 'No tests found.' ) ) ;
54+ return ;
55+ }
56+
57+ await runVitest ( mode , patterns , configs , options ) ;
4958 } ) ;
0 commit comments