From 0ee46cdc2673f9d921f14583eec34292e884cc50 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 2 Oct 2018 16:36:22 +1000 Subject: [PATCH] test: make run-as-node --inspect test more robust on windows --- spec/node-spec.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/node-spec.js b/spec/node-spec.js index bc9df5bdff93..a00730ce15df 100644 --- a/spec/node-spec.js +++ b/spec/node-spec.js @@ -221,14 +221,23 @@ describe('node feature', () => { }) let output = '' - child.stderr.on('data', (data) => { + function cleanup () { + child.stderr.removeListener('data', errorDataListener) + child.stdout.removeListener('data', outDataHandler) + } + function errorDataListener (data) { output += data - if (output.trim().startsWith('Debugger listening on ws://')) done() - }) - - child.stdout.on('data', (data) => { + if (output.trim().startsWith('Debugger listening on ws://')) { + cleanup() + done() + } + } + function outDataHandler (data) { + cleanup() done(new Error(`Unexpected output: ${data.toString()}`)) - }) + } + child.stderr.on('data', errorDataListener) + child.stdout.on('data', outDataHandler) }) it('supports js binding', (done) => {