From 6a873bf83e0553c9bae78fa71d91d5f46c9713df Mon Sep 17 00:00:00 2001 From: Ilarion Halushka Date: Wed, 12 Dec 2018 21:14:02 +0200 Subject: [PATCH 1/2] test: added test for lib/internal/util/inspector.js Test for root/internal/inspector.js to make 100% test coverage. Test checks that onError on line 19 is executed when exception is thrown --- ...inspector-send-inspector-command-exception.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/sequential/test-inspector-send-inspector-command-exception.js diff --git a/test/sequential/test-inspector-send-inspector-command-exception.js b/test/sequential/test-inspector-send-inspector-command-exception.js new file mode 100644 index 00000000000000..61202ed7a36136 --- /dev/null +++ b/test/sequential/test-inspector-send-inspector-command-exception.js @@ -0,0 +1,16 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); + +// This is to ensure that the sendInspectorCommand function calls the cb +// function if v8_enable_inspector is enabled +process.config.variables.v8_enable_inspector = 1; +const inspector = require('internal/util/inspector'); + +// Pass first argument as a String instead of cb() function to trigger +// a TypeError that will be caught and onError() will be called 1 time +inspector.sendInspectorCommand( + common.mustCall('String to trigger a TypeError'), + common.mustCall(1) +); From 9a85d4c9894fc1ab568858e71e2a4525d1aa30aa Mon Sep 17 00:00:00 2001 From: Ilarion Halushka Date: Thu, 13 Dec 2018 21:53:50 +0200 Subject: [PATCH 2/2] test: improved test-inspector-send-inspector-command-exception Pass function that will throw an exception when called. Remove 1 from common.mustCall() because 1 is a default. --- .../test-inspector-send-inspector-command-exception.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/sequential/test-inspector-send-inspector-command-exception.js b/test/sequential/test-inspector-send-inspector-command-exception.js index 61202ed7a36136..3b512cdddec4e4 100644 --- a/test/sequential/test-inspector-send-inspector-command-exception.js +++ b/test/sequential/test-inspector-send-inspector-command-exception.js @@ -8,9 +8,9 @@ const common = require('../common'); process.config.variables.v8_enable_inspector = 1; const inspector = require('internal/util/inspector'); -// Pass first argument as a String instead of cb() function to trigger -// a TypeError that will be caught and onError() will be called 1 time +// Pass first argument as a function that throws an error that will be caught +// and onError() will be called inspector.sendInspectorCommand( - common.mustCall('String to trigger a TypeError'), - common.mustCall(1) + common.mustCall(() => { throw new Error('foo'); }), + common.mustCall() );