Skip to content

Commit 73347ac

Browse files
authored
feat: make nothrow() toggleable (#1066)
closes #1029
1 parent 53718a7 commit 73347ac

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/core.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
501501
return this
502502
}
503503

504-
nothrow(): ProcessPromise {
505-
this._nothrow = true
504+
nothrow(v = true): ProcessPromise {
505+
this._nothrow = v
506506
return this
507507
}
508508

test/core.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ import {
3333
} from '../build/core.js'
3434
import {
3535
tempfile,
36+
tempdir,
3637
fs,
3738
quote,
3839
quotePowerShell,
3940
sleep,
4041
quiet,
4142
which,
43+
nothrow,
4244
} from '../build/index.js'
4345

4446
describe('core', () => {
@@ -939,6 +941,15 @@ describe('core', () => {
939941
test('nothrow() does not throw', async () => {
940942
const { exitCode } = await $`exit 42`.nothrow()
941943
assert.equal(exitCode, 42)
944+
{
945+
// Toggle
946+
try {
947+
const p = $`exit 42`.nothrow()
948+
await p.nothrow(false)
949+
} catch ({ exitCode }) {
950+
assert.equal(exitCode, 42)
951+
}
952+
}
942953
{
943954
// Deprecated.
944955
const { exitCode } = await nothrow($`exit 42`)

0 commit comments

Comments
 (0)