Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .size-limit.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"README.md",
"LICENSE"
],
"limit": "121.40 kB",
"limit": "121.45 kB",
"brotli": false,
"gzip": false
},
Expand All @@ -29,7 +29,7 @@
"build/globals.js",
"build/deno.js"
],
"limit": "812.46 kB",
"limit": "812.50 kB",
"brotli": false,
"gzip": false
},
Expand Down
4 changes: 2 additions & 2 deletions build/core.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,12 @@ var _ProcessPromise = class _ProcessPromise extends Promise {
throw new Fail("Trying to abort a process without creating one.");
this.ac.abort(reason);
}
kill(signal = $.killSignal) {
kill(signal) {
if (this.isSettled()) throw new Fail("Too late to kill the process.");
if (!this.child)
throw new Fail("Trying to kill a process without creating one.");
if (!this.pid) throw new Fail("The process pid is undefined.");
return $.kill(this.pid, signal);
return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal);
}
/**
* @deprecated Use $({halt: true})`cmd` instead.
Expand Down
2 changes: 1 addition & 1 deletion build/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export declare class ProcessPromise extends Promise<ProcessOutput> {
};
private _pipe;
abort(reason?: string): void;
kill(signal?: NodeJS.Signals | undefined): Promise<void>;
kill(signal?: NodeJS.Signals): Promise<void>;
/**
* @deprecated Use $({halt: true})`cmd` instead.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,13 @@ export class ProcessPromise extends Promise<ProcessOutput> {
this.ac.abort(reason)
}

kill(signal = $.killSignal): Promise<void> {
kill(signal?: NodeJS.Signals): Promise<void> {
if (this.isSettled()) throw new Fail('Too late to kill the process.')
if (!this.child)
throw new Fail('Trying to kill a process without creating one.')
if (!this.pid) throw new Fail('The process pid is undefined.')

return $.kill(this.pid, signal)
return $.kill(this.pid, signal || this._snapshot.killSignal || $.killSignal)
}

/**
Expand Down
14 changes: 13 additions & 1 deletion test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ describe('core', () => {
assert.ok(o.duration >= 100 && o.duration < 1000)
})

test('a signal is passed with kill() method', async () => {
test('applies custom signal if passed', async () => {
const p = $`while true; do :; done`
setTimeout(() => p.kill('SIGKILL'), 100)
let signal
Expand All @@ -1022,6 +1022,18 @@ describe('core', () => {
assert.equal(signal, 'SIGKILL')
})

test('applies `$.killSignal` if defined', async () => {
const p = $({ killSignal: 'SIGKILL' })`while true; do :; done`
setTimeout(() => p.kill(), 100)
let signal
try {
await p
} catch (p) {
signal = p.signal
}
assert.equal(signal, 'SIGKILL')
})

test('throws if too late', async () => {
const p = $`echo foo`
await p
Expand Down
Loading