Skip to content

Commit 71146c4

Browse files
test: close every rescan test watcher, so polling cannot hang the run
Polling reports the removal before the second watcher starts; the handler then threw on the missing watcher, and the one started after it kept jest alive.
1 parent 74e9967 commit 71146c4

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎test/RestartRescan.test.js‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ describe("Rescan after the event source restarts", () => {
4747
testHelper.before(done);
4848
});
4949

50+
/** @type {InstanceType<typeof Watchpack>[]} */
51+
let watchers = [];
52+
5053
afterEach((done) => {
54+
// closed here, not in the test, so a failure cannot leave one running
55+
for (const w of watchers) w.close();
56+
watchers = [];
5157
testHelper.after(done);
5258
});
5359

@@ -60,23 +66,23 @@ describe("Rescan after the event source restarts", () => {
6066
testHelper.dir("other");
6167
const file = path.join(fixtures, "a");
6268
const w = new Watchpack({ aggregateTimeout: 50 });
63-
/** @type {InstanceType<typeof Watchpack> | undefined} */
64-
let other;
69+
watchers.push(w);
70+
let finished = false;
6571
w.on("remove", (item) => {
72+
finished = true;
6673
expect(item).toBe(file);
67-
w.close();
68-
/** @type {InstanceType<typeof Watchpack>} */
69-
(other).close();
7074
done();
7175
});
7276
w.watch({ files: [file] });
7377
testHelper.tick(() => {
7478
dropRemovalOf = "a";
7579
testHelper.unlink("a");
7680
testHelper.tick(() => {
81+
// polling reports the removal by itself, before any restart
82+
if (finished) return;
7783
// a watcher starting is what restarts the event source on macOS
7884
const started = new Watchpack({});
79-
other = started;
85+
watchers.push(started);
8086
started.watch({ directories: [path.join(fixtures, "other")] });
8187
});
8288
});

0 commit comments

Comments
 (0)