Files
hyperframes/packages/cli/src/server/fileWatcher.test.ts
T
Miguel Angel Simon Sierra 1b8b2ac425 fix(studio): fix array-form keyframe writes, diamond click-deselect, and nested video sync
- fs.watch's async 'error' event had no listener, crashing the preview
  server on EMFILE (exhausted OS watch handles)
- moveKeyframeInScript/resizeKeyframedTweenInScript/removeAllKeyframesFromScript
  required object-form keyframes: {"0%": {...}}, silently no-opping on
  array-form keyframes: [{...}, {...}]
- a keyframe diamond click's auto-synthesized native click event bubbled
  to the ancestor clip's onClick, which toggles selection off when the
  clip is already selected (the state every diamond click happens in)
- the clip's trim-resize handles (z-index 4) visually and functionally
  covered any keyframe diamond within their 14px edge strip
- synthesizeFlatTweenKeyframes didn't recognize a collapsed
  duration:0 + immediateRender static hold (what remove-all-keyframes
  produces) as non-animated, so it kept showing a phantom diamond after
  Delete All Keyframes
- resolveMediaStartSeconds's fast path for elements with their own
  data-start discarded the host composition's inherited start offset,
  so a video nested inside a sub-composition played from the root
  timeline's time instead of holding until its parent scene began

Fixes #1838
2026-07-01 18:07:44 -07:00

40 lines
1.7 KiB
TypeScript

import { EventEmitter } from "node:events";
import { describe, expect, it, vi } from "vitest";
const mockWatcher = new EventEmitter() as EventEmitter & { close: () => void };
mockWatcher.close = vi.fn();
vi.mock("node:fs", () => ({
watch: vi.fn(() => mockWatcher),
}));
const { shouldWatchProjectFile, createProjectWatcher } = await import("./fileWatcher.js");
describe("shouldWatchProjectFile", () => {
it("watches files that can affect the project signature", () => {
expect(shouldWatchProjectFile("index.html")).toBe(true);
expect(shouldWatchProjectFile("src/scene.tsx")).toBe(true);
expect(shouldWatchProjectFile("assets/hero.png")).toBe(true);
expect(shouldWatchProjectFile("Dockerfile")).toBe(true);
});
it("skips generated and dependency directories excluded from signatures", () => {
expect(shouldWatchProjectFile("node_modules/pkg/index.js")).toBe(false);
expect(shouldWatchProjectFile("renders/output.mp4")).toBe(false);
expect(shouldWatchProjectFile("dist/index.html")).toBe(false);
expect(shouldWatchProjectFile(".hyperframes/cache.json")).toBe(false);
});
});
describe("createProjectWatcher", () => {
// Regression: fs.watch can fail asynchronously (e.g. EMFILE from exhausted
// OS watch handles) via an 'error' event, not a thrown exception. An
// EventEmitter 'error' with no listener crashes the whole process — this
// must degrade gracefully instead, per the sibling synchronous-failure path.
it("does not crash the process when the underlying watcher emits 'error'", () => {
createProjectWatcher("/fake/project/dir");
expect(() => mockWatcher.emit("error", new Error("EMFILE"))).not.toThrow();
expect(mockWatcher.close).toHaveBeenCalled();
});
});