From cb0b4a6bc09d1339a471fcb9002a074eb5aac3a5 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 15 Dec 2015 17:38:00 -0500 Subject: [PATCH] test: add test for debugging one line files This commit adds a regression test for debugging of single line files. Refs: https://github.com/nodejs/node/issues/4297 PR-URL: https://github.com/nodejs/node/pull/4298 Reviewed-By: Ben Noordhuis Reviewed-By: Ali Ijaz Sheikh --- test/fixtures/exports-function-with-param.js | 1 + test/parallel/test-vm-debug-context.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/fixtures/exports-function-with-param.js diff --git a/test/fixtures/exports-function-with-param.js b/test/fixtures/exports-function-with-param.js new file mode 100644 index 00000000000000..263b9064422108 --- /dev/null +++ b/test/fixtures/exports-function-with-param.js @@ -0,0 +1 @@ +module.exports = function foo(arg) { return arg; } diff --git a/test/parallel/test-vm-debug-context.js b/test/parallel/test-vm-debug-context.js index 2e86d136bea2fa..b648592eaea901 100644 --- a/test/parallel/test-vm-debug-context.js +++ b/test/parallel/test-vm-debug-context.js @@ -53,6 +53,24 @@ assert.strictEqual(vm.runInDebugContext(undefined), undefined); assert.equal(breaks, 1); })(); +// Can set listeners and breakpoints on a single line file +(function() { + const Debug = vm.runInDebugContext('Debug'); + const fn = require(common.fixturesDir + '/exports-function-with-param'); + let called = false; + + Debug.setListener(function(event, state, data) { + if (data.constructor.name === 'BreakEvent') { + called = true; + } + }); + + Debug.setBreakPoint(fn); + fn('foo'); + assert.strictEqual(Debug.showBreakPoints(fn), '(arg) { [B0]return arg; }'); + assert.strictEqual(called, true); +})(); + // See https://github.com/nodejs/node/issues/1190, fatal errors should not // crash the process. var script = common.fixturesDir + '/vm-run-in-debug-context.js';