Skip to content

Commit 0f3dc07

Browse files
authored
fix: trim stdio strings before returning when stdioStrings is set (#42)
BREAKING CHANGE: leading and trailing whitespace is no longer preserved when stdioStrings is set
1 parent 422e1b6 commit 0f3dc07

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const promiseSpawn = (cmd, args, opts = {}, extra = {}) => {
5151

5252
const stdioResult = (stdout, stderr, { stdioString, stdio }) =>
5353
stdioString ? {
54-
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout).toString() : null,
55-
stderr: isPipe(stdio, 2) ? Buffer.concat(stderr).toString() : null,
54+
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout).toString().trim() : null,
55+
stderr: isPipe(stdio, 2) ? Buffer.concat(stderr).toString().trim() : null,
5656
}
5757
: {
5858
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout) : null,

test/promise-spawn.js

+10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class MockProc extends EE {
7474
case 'pass':
7575
this.writeOut('OK :)')
7676
return this.exit(0)
77+
case 'pass-nl':
78+
this.writeOut('OK :)\n')
79+
return this.exit(0)
7780
case 'fail':
7881
this.writeOut('not ok :(')
7982
this.writeErr('Some kind of helpful error')
@@ -118,6 +121,13 @@ t.test('pass', t => t.resolveMatch(promiseSpawn('pass', [], { stdioString: true
118121
a: 1,
119122
}))
120123

124+
t.test('pass trim output', t => t.resolveMatch(promiseSpawn('pass-nl', [], { stdioString: true }), {
125+
code: 0,
126+
signal: null,
127+
stdout: 'OK :)',
128+
stderr: '',
129+
}))
130+
121131
t.test('pass, default opts', t => t.resolveMatch(promiseSpawn('pass', []), {
122132
code: 0,
123133
signal: null,

0 commit comments

Comments
 (0)