Commit 0073c51
Changed files (2)
src
test
src/core.ts
@@ -515,6 +515,18 @@ export class ProcessOutput extends Error {
return this._combined
}
+ json() {
+ return JSON.parse(this._combined)
+ }
+
+ buffer() {
+ return Buffer.from(this._combined, 'utf8')
+ }
+
+ text() {
+ return this._combined
+ }
+
valueOf() {
return this._combined.trim()
}
test/core.test.js
@@ -226,6 +226,21 @@ describe('core', () => {
assert.equal((await p).toString(), 'foo\n')
})
+ test('ProcessPromise: implements json()', async () => {
+ const p = $`echo '{"key":"value"}'`
+ assert.deepEqual((await p).json(), { key: 'value' })
+ })
+
+ test('ProcessPromise: implements text()', async () => {
+ const p = $`echo foo`
+ assert.equal((await p).toString(), 'foo\n')
+ })
+
+ test('ProcessPromise: implements buffer()', async () => {
+ const p = $`echo foo`
+ assert.equal((await p).buffer().compare(Buffer.from('foo\n', 'utf-8')), 0)
+ })
+
test('ProcessPromise: implements valueOf()', async () => {
const p = $`echo foo`
assert.equal((await p).valueOf(), 'foo')