Skip to content

Commit

Permalink
feat: make nothrow() toggleable
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jan 7, 2025
1 parent 53718a7 commit 70d166b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this
}

nothrow(): ProcessPromise {
this._nothrow = true
nothrow(v = true): ProcessPromise {
this._nothrow = v
return this
}

Expand Down
11 changes: 11 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ import {
} from '../build/core.js'
import {
tempfile,
tempdir,
fs,
quote,
quotePowerShell,
sleep,
quiet,
which,
nothrow,
} from '../build/index.js'

describe('core', () => {
Expand Down Expand Up @@ -939,6 +941,15 @@ describe('core', () => {
test('nothrow() does not throw', async () => {
const { exitCode } = await $`exit 42`.nothrow()
assert.equal(exitCode, 42)
{
// Toggle
try {
const p = $`exit 42`.nothrow()
await p.nothrow(false)
} catch ({ exitCode }) {
assert.equal(exitCode, 42)
}
}
{
// Deprecated.
const { exitCode } = await nothrow($`exit 42`)
Expand Down

0 comments on commit 70d166b

Please sign in to comment.