11import assert from 'node:assert' ;
22import { writeFile } from 'node:fs/promises' ;
3+ import { join } from 'node:path' ;
34import { platform } from 'node:process' ;
45import chokidar from 'chokidar' ;
56import { describe , test , vi } from 'vitest' ;
6- import { createIFF } from './test/fixture.js' ;
77
88async function sleep ( ms : number ) : Promise < void > {
99 // eslint-disable-next-line no-promise-executor-return
@@ -17,21 +17,19 @@ async function waitForWatcherEmitAndReportDiagnostics(): Promise<void> {
1717
1818describe ( 'runCMKInWatchMode' , ( ) => {
1919 test ( 'reports system error occurs during watching' , async ( ) => {
20- const iff = await createIFF ( {
21- 'tsconfig.json' : '{}' ,
22- 'src/a.module.css' : '.a_1 { color: red; }' ,
23- } ) ;
20+ const fixturePath = join ( process . cwd ( ) , 'fixtures' ) ;
21+ const textFilePath = join ( fixturePath , 'file.txt' ) ;
2422
2523 // On macOS, chokidar may detect 'add' events for files added before watching starts.
2624 // To avoid test flakiness, wait for a short time before starting the watcher.
2725 await sleep ( 100 ) ;
2826
2927 const { promise, resolve } = Promise . withResolvers < void > ( ) ;
3028 chokidar
31- . watch ( iff . rootDir , { ignoreInitial : true } )
29+ . watch ( fixturePath , { ignoreInitial : true } )
3230 . on ( 'change' , ( fileName ) => {
3331 console . log ( 'change event: ' , fileName ) ;
34- if ( fileName . endsWith ( 'a.module.css ' ) ) {
32+ if ( fileName . endsWith ( 'file.txt ' ) ) {
3533 globalThis . changeCount ++ ;
3634 }
3735 } )
@@ -49,13 +47,13 @@ describe('runCMKInWatchMode', () => {
4947 globalThis . changeCount = 0 ;
5048
5149 console . log ( 'update a.module.css' ) ;
52- await writeFile ( iff . join ( 'src/a.module.css' ) , '.a_1 { color: blue; } ' ) ;
50+ await writeFile ( textFilePath , '1 ' ) ;
5351 await vi . waitFor ( ( ) => {
5452 assert ( globalThis . changeCount === 1 , `Expected changeCount to be 1, but got ${ globalThis . changeCount } ` ) ;
5553 } ) ;
5654
5755 console . log ( 'update a.module.css' ) ;
58- await writeFile ( iff . join ( 'src/a.module.css' ) , '.a_1 { color: yellow; } ' ) ;
56+ await writeFile ( textFilePath , '2 ' ) ;
5957 await waitForWatcherEmitAndReportDiagnostics ( ) ;
6058 assert ( globalThis . changeCount === 2 , `Expected changeCount to be 2, but got ${ globalThis . changeCount } ` ) ;
6159 } ) ;
0 commit comments