11import { resolve } from 'path' ;
22import { Command , Option } from '@commander-js/extra-typings' ;
3+ import chalk from 'chalk' ;
34import type { VitestRunMode } from 'vitest/node' ;
4- import { resolveEitherBundleOrTab } from '../build/manifest .js' ;
5- import { runIndividualVitest } from '../testing.js' ;
5+ import { runVitest } from '../testing/runner .js' ;
6+ import { getAllTestConfigurations , getTestConfiguration } from '../testing/utils .js' ;
67import { logCommandErrorAndExit } from './commandUtils.js' ;
78
89const vitestModeOption = new Option ( '--mode <mode>' , 'Vitest Run Mode. See https://vitest.dev/guide/cli.html#mode' )
910 . choices ( [ 'test' , 'benchmark' ] as VitestRunMode [ ] )
1011 . default ( 'test' ) ;
1112
1213const watchOption = new Option ( '-w, --watch' , 'Run tests in watch mode' ) ;
13-
1414const updateOption = new Option ( '-u, --update' , 'Update snapshots' ) ;
15-
1615const coverageOption = new Option ( '--coverage' ) ;
1716
1817export const getTestCommand = ( ) => new Command ( 'test' )
@@ -24,15 +23,27 @@ export const getTestCommand = () => new Command('test')
2423 . argument ( '[directory]' , 'Directory to search for tests. If no directory is specified, the current working directory is used' )
2524 . action ( async ( directory , { mode, ...options } ) => {
2625 const fullyResolved = resolve ( directory ?? process . cwd ( ) ) ;
27- const resolveResult = await resolveEitherBundleOrTab ( fullyResolved ) ;
26+ const configResult = await getTestConfiguration ( fullyResolved , ! ! options . watch ) ;
2827
29- if ( resolveResult . severity === 'error' ) {
30- if ( resolveResult . errors . length === 0 ) {
31- logCommandErrorAndExit ( `No tab or bundle found at ${ fullyResolved } ` ) ;
32- }
28+ if ( configResult . severity === 'error' ) {
29+ logCommandErrorAndExit ( configResult ) ;
30+ }
3331
34- logCommandErrorAndExit ( resolveResult ) ;
32+ if ( configResult . config === null ) {
33+ console . log ( chalk . yellowBright ( `No tests found for in ${ fullyResolved } ` ) ) ;
34+ return ;
3535 }
3636
37- await runIndividualVitest ( mode , resolveResult . asset , options ) ;
37+ await runVitest ( mode , [ fullyResolved ] , [ configResult . config ] , options ) ;
38+ } ) ;
39+
40+ export const getTestAllCommand = ( ) => new Command ( 'testall' )
41+ . description ( 'Run all tests based on the configuration of the root vitest file' )
42+ . addOption ( vitestModeOption )
43+ . addOption ( watchOption )
44+ . addOption ( updateOption )
45+ . addOption ( coverageOption )
46+ . action ( async ( { mode, ...options } ) => {
47+ const configs = await getAllTestConfigurations ( ! ! options . watch ) ;
48+ await runVitest ( mode , undefined , configs , options ) ;
3849 } ) ;
0 commit comments