Skip to content

Commit

Permalink
fix: fill stdall store on sync spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Sep 25, 2024
1 parent b7f1ac0 commit c63c58d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
c.ee.emit('start', result, c)
if (result.stdout.length > 0) {
c.store.stdout.push(result.stdout)
c.store.stdall.push(result.stdout)
c.stdout.write(result.stdout)
c.ee.emit('stdout', result.stdout, c)
}
if (result.stderr.length > 0) {
c.store.stderr.push(result.stderr)
c.store.stdall.push(result.stderr)
c.stderr.write(result.stderr)
c.ee.emit('stderr', result.stderr, c)
}
Expand All @@ -180,7 +182,7 @@ export const invoke = (c: TSpawnCtxNormalized): TSpawnCtxNormalized => {
get stdout() { return c.store.stdout.join('') },
get stderr() { return c.store.stderr.join('') },
stdio,
get stdall() { return this.stdout + this.stderr },
get stdall() { return c.store.stdall.join('') },
duration: Date.now() - now,
ctx: c
})
Expand Down
15 changes: 7 additions & 8 deletions src/test/ts/x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ const throwError = (err: any = new Error('should have thrown')) => { throw err }
describe('$()', () => {
it('supports async flow', async () => {
const p = $`echo foo`
const o1 = (await p).toString()
const o2 = await p.stdout

assert.equal(o1, 'foo')
assert.equal(o2.trim(), 'foo')
assert.equal((await p).toString(), 'foo')
assert.equal(await p.stdout, 'foo\n')
assert.equal(await p.stderr, '')
assert.equal(await p.status, 0)
})

it('supports sync flow', () => {
const p = $({sync: true})`echo foo`
const o1 = p.toString()
const o2 = p.stdout

assert.equal(o1, 'foo')
assert.equal(o2.trim(), 'foo')
assert.equal(p.toString(), 'foo')
assert.equal(p.stdout, 'foo\n')
assert.equal(p.stderr, '')
assert.deepEqual(p.stdall, 'foo\n')
})

it('handles promises in cmd literal', async () => {
Expand Down

0 comments on commit c63c58d

Please sign in to comment.