From d536d6d3340e630e7472b45d804711769c8fe0ab Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sat, 3 Sep 2016 22:28:41 -0700 Subject: [PATCH] test: increase _debugger coverage The uncaught exception test for `_debugger.js` was not exercising some code (particularly concerning `interface_.child`) because of the synchronous nature of the test. This adds an asynchronous version to increase test coverage. PR-URL: https://github.com/nodejs/node/pull/8403 Reviewed-By: Fedor Indutny Reviewed-By: James M Snell --- test/fixtures/debug-uncaught-async.js | 18 +++++++++++++++ .../test-debug-uncaught-exception-async.js | 22 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/fixtures/debug-uncaught-async.js create mode 100644 test/parallel/test-debug-uncaught-exception-async.js diff --git a/test/fixtures/debug-uncaught-async.js b/test/fixtures/debug-uncaught-async.js new file mode 100644 index 0000000000..275f89525b --- /dev/null +++ b/test/fixtures/debug-uncaught-async.js @@ -0,0 +1,18 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const debug = require('_debugger'); + +function emit() { + const error = new Error('fhqwhgads'); + process.emit('uncaughtException', error); +} + +assert.doesNotThrow(emit); + +// Send debug.start() an argv array of length 1 to avoid code that exits +// if argv is empty. +debug.start(['sterrance']); + +setImmediate(emit); diff --git a/test/parallel/test-debug-uncaught-exception-async.js b/test/parallel/test-debug-uncaught-exception-async.js new file mode 100644 index 0000000000..29947cfd92 --- /dev/null +++ b/test/parallel/test-debug-uncaught-exception-async.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const path = require('path'); +const spawn = require('child_process').spawn; + +const emitUncaught = path.join(common.fixturesDir, 'debug-uncaught-async.js'); +const result = spawn(process.execPath, [emitUncaught], {encoding: 'utf8'}); + +var stderr = ''; +result.stderr.on('data', (data) => { + stderr += data; +}); + +result.on('close', (code) => { + const expectedMessage = + "There was an internal error in Node's debugger. Please report this bug."; + + assert.strictEqual(code, 1); + assert(stderr.includes(expectedMessage)); + assert(stderr.includes('Error: fhqwhgads')); +});