From 0640b80c978ba7c5c1fcb57b42f774de79181721 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Mon, 18 Mar 2024 09:01:18 +0300 Subject: [PATCH] feat: add `ProcessPromise.valueOf()` (#737) closes #690 --- src/core.ts | 4 ++++ test/core.test.js | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core.ts b/src/core.ts index da1c77edcf..8747379a86 100644 --- a/src/core.ts +++ b/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 } diff --git a/test/core.test.js b/test/core.test.js index 383ac7f331..8c7b756080 100644 --- a/test/core.test.js +++ b/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 {