Commit 73347ac

Anton Golub <antongolub@antongolub.com>
2025-01-07 20:53:43
feat: make `nothrow()` toggleable (#1066)
closes #1029
1 parent 53718a7
Changed files (2)
src/core.ts
@@ -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
   }
 
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`)