Skip to content

Commit dbc75ec

Browse files
committed
reduce reproduction code
1 parent 46870bc commit dbc75ec

1 file changed

Lines changed: 8 additions & 29 deletions

File tree

main.mts

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,8 @@ async function sleep(ms: number): Promise<void> {
88
return new Promise((resolve) => setTimeout(resolve, ms));
99
}
1010

11-
async function waitFor(fn: () => void): Promise<void> {
12-
return new Promise((resolve, reject) => {
13-
const intervalTimer = setInterval(() => {
14-
try {
15-
fn();
16-
clearInterval(intervalTimer);
17-
clearTimeout(timeoutTimer);
18-
resolve();
19-
} catch {
20-
// ignore
21-
}
22-
}, 50);
23-
const timeoutTimer = setTimeout(() => {
24-
clearInterval(intervalTimer);
25-
reject(new Error('Timeout waiting for condition'));
26-
}, 1000);
27-
});
28-
}
29-
3011
const rootDir = join(import.meta.dirname, 'fixtures');
31-
const file = join(rootDir, 'src', 'a.module.css');
12+
const cssModuleFile = join(rootDir, 'src', 'a.module.css');
3213

3314
// On macOS, chokidar may detect 'add' events for files added before watching starts.
3415
// To avoid test flakiness, wait for a short time before starting the watcher.
@@ -38,7 +19,7 @@ const { promise, resolve } = Promise.withResolvers<void>();
3819
const watcher = chokidar
3920
.watch(rootDir, { ignoreInitial: true })
4021
.on('change', (fileName) => {
41-
if (fileName.endsWith('src/a.module.css')) {
22+
if (fileName === cssModuleFile) {
4223
globalThis.changeCount++;
4324
}
4425
})
@@ -51,15 +32,13 @@ await sleep(100);
5132
globalThis.changeCount = 0;
5233

5334
console.log('update a.module.css');
54-
await writeFile(file, '.a_1 { color: blue; }');
55-
await waitFor(() => {
56-
assert(globalThis.changeCount === 1);
57-
});
35+
await writeFile(cssModuleFile, '.a_1 { color: blue; }');
36+
await sleep(1000); // Wait for chokidar to process the change event
37+
assert(globalThis.changeCount === 1);
5838

5939
console.log('update a.module.css');
60-
await writeFile(file, '.a_1 { color: yellow; }');
61-
await waitFor(() => {
62-
assert(globalThis.changeCount === 2);
63-
});
40+
await writeFile(cssModuleFile, '.a_1 { color: yellow; }');
41+
await sleep(1000); // Wait for chokidar to process the change event
42+
assert(globalThis.changeCount === 2);
6443

6544
await watcher.close();

0 commit comments

Comments
 (0)