From 2e7517a9b04846182e4d176d4388b96bb28b3713 Mon Sep 17 00:00:00 2001 From: Szymon Kaliski Date: Mon, 6 May 2024 10:23:54 +0200 Subject: [PATCH] also compare buffers for env --- index.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.test.ts b/index.test.ts index 5f72518..16e23cf 100644 --- a/index.test.ts +++ b/index.test.ts @@ -233,11 +233,11 @@ describe('PTY', () => { test('respects env', (done) => { const message = 'hello from env'; - let buffer = ''; + let buffer: Buffer | undefined; const pty = new Pty( '/bin/sh', - ['-c', 'sleep 0.1s && echo $ENV_VARIABLE && exit'], + ['-c', 'echo $ENV_VARIABLE && exit'], { ENV_VARIABLE: message, }, @@ -246,7 +246,8 @@ describe('PTY', () => { (err, exitCode) => { expect(err).toBeNull(); expect(exitCode).toBe(0); - expect(buffer).toBe(message + '\r\n'); + assert(buffer); + expect(Buffer.compare(buffer, Buffer.from(message + '\r\n'))).toBe(0); pty.close(); done(); @@ -256,7 +257,8 @@ describe('PTY', () => { const readStream = fs.createReadStream('', { fd: pty.fd() }); readStream.on('data', (chunk) => { - buffer += chunk.toString(); + assert(Buffer.isBuffer(chunk)); + buffer = chunk; }); readStream.on('error', (err: any) => { if (err.code && err.code.indexOf('EIO') !== -1) {