mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-21 07:45:38 +00:00
test(server): wait for file observation before atomic replacement (#10372)
Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { mkdir, mkdtemp, rename, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { basename, dirname, join, sep } from "node:path";
|
||||
import { afterEach, expect, test, vi } from "vitest";
|
||||
import { createWatcherLivenessCanary } from "../watcher-liveness-canary.js";
|
||||
import {
|
||||
createFileObserver,
|
||||
type FileChange,
|
||||
@@ -167,12 +168,17 @@ test("survives atomic replacement and remains observable", async () => {
|
||||
const root = await createRoot();
|
||||
const target = join(root, "target.txt");
|
||||
await writeFile(target, "before");
|
||||
const canary = createWatcherLivenessCanary(root);
|
||||
const events: FileChange[] = [];
|
||||
const subscription = await subscribeToFileChanges(root, (error, batch) => {
|
||||
expect(error).toBeNull();
|
||||
events.push(...batch);
|
||||
events.push(...canary.filterEvents(batch));
|
||||
});
|
||||
|
||||
// macOS starts delivering native events asynchronously after subscription.
|
||||
await canary.verify();
|
||||
events.length = 0;
|
||||
|
||||
const replacement = join(root, "replacement.txt");
|
||||
await writeFile(replacement, "after");
|
||||
await rename(replacement, target);
|
||||
|
||||
Reference in New Issue
Block a user