Skip to content

Commit c725e9f

Browse files
committed
Added a test for kill
1 parent 727bea2 commit c725e9f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

process/test/exec.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,33 @@ describe("handles env vars", () => {
477477

478478
// Close the main "handles env vars" describe block
479479
});
480+
481+
describe("kill", () => {
482+
it("can explicitly kill a running process", function* () {
483+
let proc: Process = yield* exec("deno run -A './fixtures/echo-server.ts'", {
484+
env: {
485+
PORT: "29001",
486+
PATH: process.env.PATH as string,
487+
...(SystemRoot ? { SystemRoot } : {}),
488+
},
489+
cwd: import.meta.dirname,
490+
});
491+
492+
// Wait for the server to start
493+
yield* expectMatch(/listening/, lines()(proc.stdout));
494+
495+
// Kill the process
496+
yield* proc.kill();
497+
498+
// Join should complete after kill
499+
let status = yield* proc.join();
500+
501+
// On POSIX systems, a killed process should have a signal set
502+
if (process.platform !== "win32") {
503+
expect(status.signal).toBeDefined();
504+
} else {
505+
// On Windows, it might be an exit code instead
506+
expect(status.code !== 0 || status.signal).toBeTruthy();
507+
}
508+
});
509+
});

0 commit comments

Comments
 (0)