@@ -12,14 +12,14 @@ function getCwd(testFile: string) {
1212 return path . dirname ( configFilePath ) ;
1313}
1414
15- function buildVitestArgs ( { caseName, casePath, sanitize = true } : { caseName : string , casePath : string , sanitize ?: boolean } ) {
15+ function buildVitestArgs ( { caseName, casePath, sanitize = true , command = 'run' } : { caseName : string , casePath : string , sanitize ?: boolean , command ?: 'run' | 'watch' } ) {
1616 let sanitizedCasePath = casePath ;
1717 if ( sanitize ) {
1818 sanitizedCasePath = JSON . stringify ( casePath ) ;
1919 caseName = JSON . stringify ( caseName ) ;
2020 }
2121
22- const args = [ 'vitest' , 'run' , '--testNamePattern' , caseName , sanitizedCasePath ] ;
22+ const args = [ 'vitest' , command , '--testNamePattern' , caseName , sanitizedCasePath ] ;
2323
2424 const rootDir = getCwd ( casePath ) ;
2525 if ( rootDir ) {
@@ -57,6 +57,28 @@ export async function runInTerminal(text: string, filename: string) {
5757 terminal . show ( ) ;
5858}
5959
60+ export async function watchInTerminal ( text : string , filename : string ) {
61+ let terminalAlreadyExists = true ;
62+ if ( ! terminal || terminal . exitStatus ) {
63+ terminalAlreadyExists = false ;
64+ terminal ?. dispose ( ) ;
65+ terminal = vscode . window . createTerminal ( `vscode-vitest-runner` ) ;
66+ }
67+
68+ const vitestArgs = buildVitestArgs ( { command : 'watch' , caseName : text , casePath : filename } ) ;
69+ const npxArgs = [ 'npx' , ...vitestArgs ] ;
70+
71+ if ( terminalAlreadyExists ) {
72+ // CTRL-C to stop the previous run
73+ terminal . sendText ( '\x03' ) ;
74+ }
75+
76+ await saveFile ( filename ) ;
77+
78+ terminal . sendText ( npxArgs . join ( ' ' ) , true ) ;
79+ terminal . show ( ) ;
80+ }
81+
6082function buildDebugConfig (
6183 casePath : string ,
6284 text : string
0 commit comments