Skip to content

Commit b203e57

Browse files
committed
Refactor wait function to use a default timeout and remove hardcoded timeout values from tests.
1 parent cfdccdc commit b203e57

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

test/test.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ after(() => {
3333
* @param {Function} fn - Assertion function
3434
* @param {number} timeout - Timeout in milliseconds
3535
*/
36-
function wait(fn, timeout) {
36+
function wait(fn, timeout = 450) {
3737
try {
3838
fn();
3939
} catch (error) {
@@ -137,7 +137,7 @@ describe('watch for files', () => {
137137
wait(() => {
138138
assert.strictEqual(times, 1);
139139
done();
140-
}, 250);
140+
});
141141
});
142142
});
143143

@@ -175,12 +175,12 @@ describe('watch for files', () => {
175175
}
176176
} else {
177177
assert.deepStrictEqual(
178-
changes,
179-
[tree.getPath(newfile1), tree.getPath(newfile2)]
178+
changes.sort(),
179+
[tree.getPath(newfile1), tree.getPath(newfile2)].sort()
180180
);
181181
}
182182
done();
183-
}, 100);
183+
});
184184
});
185185
});
186186

@@ -216,7 +216,7 @@ describe('watch for directories', () => {
216216
wait(() => {
217217
assert.deepStrictEqual(events, ['remove']);
218218
done();
219-
}, 400);
219+
});
220220
});
221221
});
222222

@@ -255,7 +255,7 @@ describe('watch for directories', () => {
255255
watcher.on('ready', () => {
256256
tree.newFile('home/ignored/file');
257257
tree.modify('home/ignored/file', 100);
258-
wait(done, 150);
258+
wait(done);
259259
});
260260
});
261261

@@ -278,7 +278,7 @@ describe('watch for directories', () => {
278278
wait(() => {
279279
assert.deepStrictEqual(events, [dir, file1, file2]);
280280
done();
281-
}, 300);
281+
});
282282
});
283283
});
284284

@@ -297,7 +297,7 @@ describe('watch for directories', () => {
297297
wait(() => {
298298
assert.deepStrictEqual(events, ['update']);
299299
done();
300-
}, 350);
300+
});
301301
});
302302
});
303303

@@ -497,7 +497,7 @@ describe('options', () => {
497497
assert(matchRegularDir, 'watch failed to detect regular file');
498498
assert(!matchIgnoredDir, 'fail to ignore path `deep_node_modules`');
499499
done();
500-
}, 100);
500+
});
501501
});
502502
});
503503

@@ -530,7 +530,7 @@ describe('options', () => {
530530
assert.strictEqual(times, 1, 'should only report /home/bb/file2 once');
531531
assert.strictEqual(matchIgnoredFile, false, 'home/bb/file1 should be ignored');
532532
done();
533-
}, 100);
533+
});
534534
});
535535
});
536536

@@ -561,7 +561,7 @@ describe('options', () => {
561561
assert(times, 1, 'report file2');
562562
assert(!matchIgnoredFile, 'home/bb/file1 should be ignored');
563563
done();
564-
}, 100);
564+
});
565565
});
566566
});
567567

@@ -677,11 +677,11 @@ describe('parameters', () => {
677677

678678
wait(() => {
679679
assert.deepStrictEqual(
680-
changes,
681-
[tree.getPath(file1), tree.getPath(file2)]
680+
changes.sort(),
681+
[tree.getPath(file1), tree.getPath(file2)].sort()
682682
);
683683
done();
684-
}, 200);
684+
});
685685
});
686686
});
687687
});
@@ -722,7 +722,7 @@ describe('watcher object', () => {
722722
assert(watcher.isClosed(), 'watcher should be closed');
723723
assert.strictEqual(times, 0, 'failed to close the watcher');
724724
done();
725-
}, 150);
725+
});
726726
});
727727
});
728728

@@ -757,7 +757,7 @@ describe('watcher object', () => {
757757
assert(watcher.isClosed(), 'watcher should be closed');
758758
assert.strictEqual(times, 0, 'failed to close the watcher');
759759
done();
760-
}, 100);
760+
});
761761
});
762762
});
763763
});

0 commit comments

Comments
 (0)