From c63c58deae9c9bd79c16d18b1431895db3cbdf42 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Wed, 25 Sep 2024 18:33:53 +0300 Subject: [PATCH] fix: fill stdall store on sync spawn --- src/main/ts/spawn.ts | 4 +++- src/test/ts/x.test.ts | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/ts/spawn.ts b/src/main/ts/spawn.ts index fff406f..6b91f43 100644 --- a/src/main/ts/spawn.ts +++ b/src/main/ts/spawn.ts @@ -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) } @@ -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 }) diff --git a/src/test/ts/x.test.ts b/src/test/ts/x.test.ts index cee4fc1..cb80046 100644 --- a/src/test/ts/x.test.ts +++ b/src/test/ts/x.test.ts @@ -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 () => {