perf(test): keep single media server and fast cleanup

This commit is contained in:
Peter Steinberger
2026-02-15 00:54:37 +00:00
parent e211b75475
commit 7e065d90f0
2 changed files with 25 additions and 31 deletions

View File

@@ -63,9 +63,15 @@ export function attachMediaRoutes(
res.send(data);
// best-effort single-use cleanup after response ends
res.on("finish", () => {
setTimeout(() => {
fs.rm(realPath).catch(() => {});
}, 50);
const cleanup = () => {
void fs.rm(realPath).catch(() => {});
};
// Tests should not pay for time-based cleanup delays.
if (process.env.VITEST || process.env.NODE_ENV === "test") {
queueMicrotask(cleanup);
return;
}
setTimeout(cleanup, 50);
});
} catch (err) {
if (err instanceof SafeOpenError) {