@@ -8,6 +8,16 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
88import { createBundleFile } from './bundle.ts' ;
99import { watchDir , makeWatchEvents } from './watch.ts' ;
1010
11+ const mocks = vi . hoisted ( ( ) => ( {
12+ logger : {
13+ log : vi . fn ( ) ,
14+ error : vi . fn ( ) ,
15+ info : vi . fn ( ) ,
16+ warn : vi . fn ( ) ,
17+ debug : vi . fn ( ) ,
18+ } ,
19+ } ) ) ;
20+
1121vi . mock ( 'fs/promises' , ( ) => ( {
1222 unlink : vi . fn ( async ( ) => new Promise < void > ( ( ) => undefined ) ) ,
1323} ) ) ;
@@ -20,9 +30,13 @@ vi.mock('./bundle.ts', () => ({
2030 createBundleFile : vi . fn ( async ( ) => new Promise < void > ( ( ) => undefined ) ) ,
2131} ) ) ;
2232
33+ vi . mock ( '../logger.ts' , ( ) => ( {
34+ logger : mocks . logger ,
35+ } ) ) ;
36+
2337vi . mock ( 'chokidar' , ( ) => ( {
2438 watch : ( ) => {
25- console . log ( 'returning watcher...' ) ;
39+ mocks . logger . log ( 'returning watcher...' ) ;
2640 const watcher = {
2741 on : ( ) => watcher ,
2842 close : async ( ) : Promise < void > => undefined ,
@@ -99,26 +113,25 @@ describe('makeWatchEvents', () => {
99113 expect ( unlink ) . toHaveBeenLastCalledWith ( `resolved:${ testPath } ` ) ;
100114 } ) ;
101115
102- it ( 'calls console .info on success' , async ( ) => {
116+ it ( 'calls logger .info on success' , async ( ) => {
103117 const promise = Promise . resolve ( ) ;
104118 vi . mocked ( unlink ) . mockReturnValue ( promise ) ;
105119
106120 const events = makeWatchEvents ( watch ( '.' ) , vi . fn ( ) , vi . fn ( ) ) ;
107121 const testPath = 'test-path' ;
108- const infoSpy = vi . spyOn ( console , 'info' ) ;
109122
110123 events . unlink ( testPath ) ;
111124
112125 // wait for next crank turn
113126 await Promise . resolve ( ) ;
114127
115- expect ( infoSpy ) . toHaveBeenCalledTimes ( 2 ) ;
116- expect ( infoSpy ) . toHaveBeenNthCalledWith (
128+ expect ( mocks . logger . info ) . toHaveBeenCalledTimes ( 2 ) ;
129+ expect ( mocks . logger . info ) . toHaveBeenNthCalledWith (
117130 1 ,
118131 'Source file removed:' ,
119132 testPath ,
120133 ) ;
121- expect ( infoSpy ) . toHaveBeenNthCalledWith (
134+ expect ( mocks . logger . info ) . toHaveBeenNthCalledWith (
122135 2 ,
123136 `removed resolved:${ testPath } ` ,
124137 ) ;
0 commit comments