Browse Source

test: make run-as-node --inspect test more robust on windows

Samuel Attard 6 years ago
parent
commit
0ee46cdc26
1 changed files with 15 additions and 6 deletions
  1. 15 6
      spec/node-spec.js

+ 15 - 6
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) => {