import { QuickJSWorker } from "../dist"; describe("Process liveness compatibility", () => { let worker: QuickJSWorker & { _native: { ref: () => void; unref: () => void } }; beforeEach(() => { worker = new QuickJSWorker() as QuickJSWorker & { _native: { ref: () => void; unref: () => void } }; }); afterEach(async () => { if (worker && !worker.isClosed()) await worker.close(); }); it("refs and unreferences the native channel around async eval", async () => { const refSpy = jest.spyOn(worker._native, "ref"); const unrefSpy = jest.spyOn(worker._native, "unref"); await expect(worker.eval("40 + 2")).resolves.toBe(42); expect(refSpy).toHaveBeenCalled(); expect(unrefSpy).toHaveBeenCalled(); }); it("refs and unreferences the native channel around handle calls and disposal", async () => { const handle = await worker.handle.eval("(x) => x + 1"); const refSpy = jest.spyOn(worker._native, "ref"); const unrefSpy = jest.spyOn(worker._native, "unref"); await expect(handle.call([41])).resolves.toBe(42); await handle.dispose(); expect(refSpy).toHaveBeenCalled(); expect(unrefSpy).toHaveBeenCalled(); }); });