Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion test/DirectoryWatcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@ describe("DirectoryWatcher", () => {
});
});

const IS_OSX = require("os").platform() === "darwin";

/** @type {Record<"slow" | "fast", number>} */
// FSEvents coalesces rapid changes, so on macOS the "fast" case needs a
// larger interval or consecutive writes will be dropped.
const timings = {
slow: 300,
fast: 50,
fast: IS_OSX ? 150 : 50,
};
for (const name of Object.keys(timings)) {
const time = timings[/** @type {keyof typeof timings} */ (name)];
Expand Down
13 changes: 9 additions & 4 deletions test/helpers/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const writeFileAtomic = require("write-file-atomic");

const watchEventSource = require("../../lib/watchEventSource");

const IS_OSX = require("os").platform() === "darwin";

require("../../lib/getWatcherManager");
let watcherManagerModule =
require.cache[require.resolve("../../lib/getWatcherManager")];
Expand Down Expand Up @@ -48,7 +50,10 @@ class TestHelper {
*/
tick(arg, fn) {
// if polling is set, ensure the tick is longer than the polling interval.
const defaultTick = (Number(process.env.WATCHPACK_POLLING) || 100) + 10;
// On macOS the FSEvents dispatch cycle is ~100-500ms, so use a larger
// default tick there to keep fs.watch-based tests stable.
const defaultTick =
(Number(process.env.WATCHPACK_POLLING) || (IS_OSX ? 250 : 100)) + 10;

if (typeof arg === "function") {
fn = arg;
Expand All @@ -66,7 +71,7 @@ class TestHelper {
*/
before(done) {
checkAllWatcherClosed();
this.tick(400, () => {
this.tick(IS_OSX ? 700 : 400, () => {
this.rm(this.testdir);
fs.mkdirSync(this.testdir);
done();
Expand All @@ -88,10 +93,10 @@ class TestHelper {
return;
}
checkAllWatcherClosed();
this.tick(300, done);
this.tick(IS_OSX ? 500 : 300, done);
};

this.tick(300, () => {
this.tick(IS_OSX ? 500 : 300, () => {
del();
});
}
Expand Down
Loading