diff --git a/src/core.ts b/src/core.ts index 884e901e18..643e8027ce 100644 --- a/src/core.ts +++ b/src/core.ts @@ -501,8 +501,8 @@ export class ProcessPromise extends Promise { return this } - nothrow(): ProcessPromise { - this._nothrow = true + nothrow(v = true): ProcessPromise { + this._nothrow = v return this } diff --git a/test/core.test.js b/test/core.test.js index a6b34c9868..b8a7c6e807 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -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', () => { @@ -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`)