@@ -2,6 +2,7 @@ import path from 'node:path'
22
33import makeConsoleMock from 'consolemock'
44import { SubprocessError } from 'nano-spawn'
5+ import { exec } from 'tinyexec'
56import { afterAll , afterEach , beforeAll , describe , it , vi } from 'vitest'
67
78import { normalizePath } from '../../lib/normalizePath.js'
@@ -11,6 +12,14 @@ import { mockNanoSpawnReturnValue } from './__utils__/mockNanoSpawnReturnValue.j
1112
1213const { default : spawn } = await getMockNanoSpawn ( )
1314
15+ vi . mock ( 'tinyexec' , ( ) => ( {
16+ exec : vi . fn ( ) . mockReturnValue ( {
17+ async * [ Symbol . asyncIterator ] ( ) {
18+ yield 'test'
19+ } ,
20+ } ) ,
21+ } ) )
22+
1423vi . mock ( '../../lib/getStagedFiles.js' , ( ) => ( {
1524 getStagedFiles : vi . fn ( async ( ) => [ ] ) ,
1625} ) )
@@ -177,13 +186,6 @@ describe('runAll', () => {
177186 '' : { '*.js' : 'echo "sample"' } ,
178187 } ) )
179188
180- spawn . mockImplementationOnce ( ( ) =>
181- mockNanoSpawnReturnValue ( {
182- output : 'Has staged files' ,
183- nodeChildProcess : { pid : 0 } ,
184- } )
185- )
186-
187189 mockGitWorkflow . runTasks . mockImplementationOnce ( async ( ctx , task , { listrTasks } ) => {
188190 ctx . errors . add ( TaskError )
189191 return task . newListr ( listrTasks )
@@ -202,13 +204,6 @@ describe('runAll', () => {
202204 '' : { '*.js' : 'echo "sample"' } ,
203205 } ) )
204206
205- spawn . mockImplementationOnce ( ( ) =>
206- mockNanoSpawnReturnValue ( {
207- output : 'Has staged files' ,
208- nodeChildProcess : { pid : 0 } ,
209- } )
210- )
211-
212207 spawn . mockImplementationOnce ( ( ) =>
213208 mockNanoSpawnReturnValue (
214209 Object . assign ( new SubprocessError ( ) , {
@@ -433,12 +428,7 @@ describe('runAll', () => {
433428 } ) )
434429
435430 // Mock first spawn call (git operations) to succeed
436- spawn . mockImplementationOnce ( ( ) =>
437- mockNanoSpawnReturnValue ( {
438- output : 'Success' ,
439- nodeChildProcess : { pid : 0 } ,
440- } )
441- )
431+ vi . mocked ( exec ) . mockResolvedValueOnce ( 'Has staged files' )
442432
443433 // Mock second spawn call (the actual task) to fail
444434 spawn . mockImplementationOnce ( ( ) =>
@@ -475,12 +465,7 @@ describe('runAll', () => {
475465 } ) )
476466
477467 // Mock first spawn call (git operations) to succeed
478- spawn . mockImplementationOnce ( ( ) =>
479- mockNanoSpawnReturnValue ( {
480- output : 'Success' ,
481- nodeChildProcess : { pid : 0 } ,
482- } )
483- )
468+ vi . mocked ( exec ) . mockResolvedValueOnce ( 'Has staged files' )
484469
485470 // Mock second spawn call (`echo "success js command 1"`) to succeed
486471 spawn . mockImplementationOnce ( ( ) =>
0 commit comments