Commit 0640b80

Anton Golub <antongolub@antongolub.com>
2024-03-18 07:01:18
feat: add `ProcessPromise.valueOf()` (#737)
closes #690
1 parent b38972e
Changed files (2)
src/core.ts
@@ -448,6 +448,10 @@ export class ProcessOutput extends Error {
     return this._combined
   }
 
+  valueOf() {
+    return this._combined.trim()
+  }
+
   get stdout() {
     return this._stdout
   }
test/core.test.js
@@ -188,6 +188,17 @@ describe('core', () => {
     assert.ok(p5 !== p1)
   })
 
+  test('ProcessPromise: implements toString()', async () => {
+    const p = $`echo foo`
+    assert.equal((await p).toString(), 'foo\n')
+  })
+
+  test('ProcessPromise: implements valueOf()', async () => {
+    const p = $`echo foo`
+    assert.equal((await p).valueOf(), 'foo')
+    assert.ok((await p) == 'foo')
+  })
+
   test('cd() works with relative paths', async () => {
     let cwd = process.cwd()
     try {