UNPKG

posix-node

Version:

Missing Posix Functions for Node.js (via a native module written in Zig)

48 lines 2.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = __importDefault(require("./index")); test("posix_spawn /bin/sleep and wait for it to finish using waitpid and confirm the time", () => { const t0 = new Date().valueOf(); const pid = index_1.default.posix_spawn?.("/bin/sleep", null, null, ["/bin/sleep", "0.5"], {}); if (pid == null) { throw Error("pid must be a positive integer"); } const x = index_1.default.waitpid?.(pid, 0); if (x == null) { throw Error("waitpid must return something"); } const { ret, wstatus } = x; expect(ret).toBe(pid); expect(wstatus).toBe(0); const tm = new Date().valueOf() - t0; expect(tm > 400 && tm < 1000).toBe(true); }); test("posix_spawnp sleep and wait for it to finish using waitpid and confirm the time", () => { const t0 = new Date().valueOf(); const pid = index_1.default.posix_spawnp?.("sleep", null, null, ["sleep", "0.5"], {}); if (pid == null) { throw Error("pid must be a positive integer"); } const x = index_1.default.waitpid?.(pid, 0); if (x == null) { throw Error("waitpid must return something"); } const { ret, wstatus } = x; expect(ret).toBe(pid); expect(wstatus).toBe(0); const tm = new Date().valueOf() - t0; expect(tm > 400 && tm < 1000).toBe(true); }); test("calling posix_spawnp with invalid fd arg to addclose to throw", () => { expect(() => index_1.default.posix_spawnp?.("sleep", [["addclose", -1]], {}, ["sleep", "3"], {})).toThrow("posix_spawn_file_actions_addclose failed"); }); test("calling posix_spawnp with invalid new_fd arg to adddup2 to throw", () => { expect(() => index_1.default.posix_spawnp?.("sleep", [["adddup2", 1, -100]], {}, ["sleep", "3"], {})).toThrow("posix_spawn_file_actions_adddup2 failed"); }); test("calling posix_spawnp with invalid fd arg to addopen to throw", () => { expect(() => index_1.default.posix_spawnp?.("sleep", [["addopen", -1, "/tmp/a", 0, 0]], {}, ["sleep", "3"], {})).toThrow("posix_spawn_file_actions_addopen failed"); }); //# sourceMappingURL=spawn.test.js.map