Tests: stabilize file watchers
This commit is contained in:
@@ -231,7 +231,7 @@ describe("canvas host", () => {
|
|||||||
await server.close();
|
await server.close();
|
||||||
await fs.rm(dir, { recursive: true, force: true });
|
await fs.rm(dir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
}, 10_000);
|
||||||
|
|
||||||
it("serves the gateway-hosted A2UI scaffold", async () => {
|
it("serves the gateway-hosted A2UI scaffold", async () => {
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-canvas-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-canvas-"));
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ export async function createCanvasHostHandler(
|
|||||||
? chokidar.watch(rootReal, {
|
? chokidar.watch(rootReal, {
|
||||||
ignoreInitial: true,
|
ignoreInitial: true,
|
||||||
awaitWriteFinish: { stabilityThreshold: 75, pollInterval: 10 },
|
awaitWriteFinish: { stabilityThreshold: 75, pollInterval: 10 },
|
||||||
|
usePolling: opts.allowInTests === true,
|
||||||
ignored: [
|
ignored: [
|
||||||
/(^|[\\/])\../, // dotfiles
|
/(^|[\\/])\../, // dotfiles
|
||||||
/(^|[\\/])node_modules([\\/]|$)/,
|
/(^|[\\/])node_modules([\\/]|$)/,
|
||||||
|
|||||||
@@ -360,13 +360,18 @@ export function startGatewayConfigReloader(opts: {
|
|||||||
const watcher = chokidar.watch(opts.watchPath, {
|
const watcher = chokidar.watch(opts.watchPath, {
|
||||||
ignoreInitial: true,
|
ignoreInitial: true,
|
||||||
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
|
awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
|
||||||
|
usePolling: Boolean(process.env.VITEST),
|
||||||
});
|
});
|
||||||
|
|
||||||
watcher.on("add", schedule);
|
watcher.on("add", schedule);
|
||||||
watcher.on("change", schedule);
|
watcher.on("change", schedule);
|
||||||
watcher.on("unlink", schedule);
|
watcher.on("unlink", schedule);
|
||||||
|
let watcherClosed = false;
|
||||||
watcher.on("error", (err) => {
|
watcher.on("error", (err) => {
|
||||||
|
if (watcherClosed) return;
|
||||||
|
watcherClosed = true;
|
||||||
opts.log.warn(`config watcher error: ${String(err)}`);
|
opts.log.warn(`config watcher error: ${String(err)}`);
|
||||||
|
void watcher.close().catch(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -374,6 +379,7 @@ export function startGatewayConfigReloader(opts: {
|
|||||||
stopped = true;
|
stopped = true;
|
||||||
if (debounceTimer) clearTimeout(debounceTimer);
|
if (debounceTimer) clearTimeout(debounceTimer);
|
||||||
debounceTimer = null;
|
debounceTimer = null;
|
||||||
|
watcherClosed = true;
|
||||||
await watcher.close().catch(() => {});
|
await watcher.close().catch(() => {});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user