32 lines
938 B
TypeScript
32 lines
938 B
TypeScript
import { afterEach, describe, expect, test } from "bun:test";
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { serviceStatus } from "./service.js";
|
|
|
|
const tempDirs: string[] = [];
|
|
|
|
afterEach(() => {
|
|
for (const dir of tempDirs.splice(0)) {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
describe("service lifecycle state", () => {
|
|
test("clears a stale pid file instead of reporting another process as running", () => {
|
|
const stateDir = mkdtempSync(join(tmpdir(), "seal-use-service-"));
|
|
tempDirs.push(stateDir);
|
|
writeFileSync(join(stateDir, "service.pid"), "999999\n");
|
|
|
|
const status = serviceStatus({
|
|
appRoot: "/tmp/seal-use",
|
|
entryFile: "/tmp/seal-use/src/cli.ts",
|
|
stateDir,
|
|
version: "0.4.2"
|
|
});
|
|
|
|
expect(status.running).toBe(false);
|
|
expect(status.pid).toBeUndefined();
|
|
});
|
|
});
|