Skip to content

Commit

Permalink
fix: trim stdio strings before returning when stdioStrings is set (#42)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: leading and trailing whitespace is no longer preserved when stdioStrings is set
  • Loading branch information
nlf committed Oct 26, 2022
1 parent 422e1b6 commit 0f3dc07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Expand Up @@ -51,8 +51,8 @@ const promiseSpawn = (cmd, args, opts = {}, extra = {}) => {

const stdioResult = (stdout, stderr, { stdioString, stdio }) =>
stdioString ? {
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout).toString() : null,
stderr: isPipe(stdio, 2) ? Buffer.concat(stderr).toString() : null,
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout).toString().trim() : null,
stderr: isPipe(stdio, 2) ? Buffer.concat(stderr).toString().trim() : null,
}
: {
stdout: isPipe(stdio, 1) ? Buffer.concat(stdout) : null,
Expand Down
10 changes: 10 additions & 0 deletions test/promise-spawn.js
Expand Up @@ -74,6 +74,9 @@ class MockProc extends EE {
case 'pass':
this.writeOut('OK :)')
return this.exit(0)
case 'pass-nl':
this.writeOut('OK :)\n')
return this.exit(0)
case 'fail':
this.writeOut('not ok :(')
this.writeErr('Some kind of helpful error')
Expand Down Expand Up @@ -118,6 +121,13 @@ t.test('pass', t => t.resolveMatch(promiseSpawn('pass', [], { stdioString: true
a: 1,
}))

t.test('pass trim output', t => t.resolveMatch(promiseSpawn('pass-nl', [], { stdioString: true }), {
code: 0,
signal: null,
stdout: 'OK :)',
stderr: '',
}))

t.test('pass, default opts', t => t.resolveMatch(promiseSpawn('pass', []), {
code: 0,
signal: null,
Expand Down

0 comments on commit 0f3dc07

Please sign in to comment.