perf(test): fold restart recovery helper into spawn utils suite

This commit is contained in:
Peter Steinberger
2026-02-15 23:51:04 +00:00
parent c82dc02b4d
commit 725f63f724
2 changed files with 17 additions and 18 deletions

View File

@@ -1,18 +0,0 @@
import { describe, expect, it, vi } from "vitest";
import { createRestartIterationHook } from "./restart-recovery.js";
describe("restart-recovery", () => {
it("skips recovery on first iteration and runs on subsequent iterations", () => {
const onRestart = vi.fn();
const onIteration = createRestartIterationHook(onRestart);
expect(onIteration()).toBe(false);
expect(onRestart).not.toHaveBeenCalled();
expect(onIteration()).toBe(true);
expect(onRestart).toHaveBeenCalledTimes(1);
expect(onIteration()).toBe(true);
expect(onRestart).toHaveBeenCalledTimes(2);
});
});

View File

@@ -2,6 +2,7 @@ import type { ChildProcess } from "node:child_process";
import { EventEmitter } from "node:events";
import { PassThrough } from "node:stream";
import { describe, expect, it, vi } from "vitest";
import { createRestartIterationHook } from "./restart-recovery.js";
import { spawnWithFallback } from "./spawn-utils.js";
function createStubChild() {
@@ -61,3 +62,19 @@ describe("spawnWithFallback", () => {
expect(spawnMock).toHaveBeenCalledTimes(1);
});
});
describe("restart-recovery", () => {
it("skips recovery on first iteration and runs on subsequent iterations", () => {
const onRestart = vi.fn();
const onIteration = createRestartIterationHook(onRestart);
expect(onIteration()).toBe(false);
expect(onRestart).not.toHaveBeenCalled();
expect(onIteration()).toBe(true);
expect(onRestart).toHaveBeenCalledTimes(1);
expect(onIteration()).toBe(true);
expect(onRestart).toHaveBeenCalledTimes(2);
});
});