From 29470f8fffa9744eb2cd5960460c70ca5407eed5 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 13 Sep 2016 11:38:55 -0700 Subject: [PATCH 1/2] test: add coverage for client._addHandle() `Client.prototype._addHandle()` in the `_debugger` module has conditions around invalid properties that are not currently tested. This change adds some minimal unit tests. --- .../test-debugger-client-addhandle.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/parallel/test-debugger-client-addhandle.js diff --git a/test/parallel/test-debugger-client-addhandle.js b/test/parallel/test-debugger-client-addhandle.js new file mode 100644 index 00000000000000..47390fa44068ea --- /dev/null +++ b/test/parallel/test-debugger-client-addhandle.js @@ -0,0 +1,44 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const Client = require('_debugger').Client; + +{ + const client = new Client(); + assert.deepStrictEqual(client.handles, {}); +} + +{ + const client = new Client(); + client._addHandle(null); + assert.deepStrictEqual(client.handles, {}); +} + +{ + const client = new Client(); + client._addHandle('not an object'); + assert.deepStrictEqual(client.handles, {}); +} + +{ + const client = new Client(); + client._addHandle({handle: 'not a number'}); + assert.deepStrictEqual(client.handles, {}); +} + +{ + const client = new Client(); + const validNoScript = { handle: 6, id: 'foo', type: 'not a script' }; + client._addHandle(validNoScript); + assert.deepStrictEqual(client.handles, { 6: validNoScript }); + assert.deepStrictEqual(client.scripts, {}); +} + +{ + const client = new Client(); + const validWithScript = { handle: 5, id: 'bar', type: 'script' }; + client._addHandle(validWithScript); + assert.deepStrictEqual(client.handles, { 5: validWithScript }); + assert.deepStrictEqual(client.scripts, { bar: validWithScript }); +} From c8478b1fa11c77f9d4d69d477ed5e06c6b920f6c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 13 Sep 2016 16:53:58 -0700 Subject: [PATCH 2/2] squash: formatting --- test/parallel/test-debugger-client-addhandle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-debugger-client-addhandle.js b/test/parallel/test-debugger-client-addhandle.js index 47390fa44068ea..bb953561b945a9 100644 --- a/test/parallel/test-debugger-client-addhandle.js +++ b/test/parallel/test-debugger-client-addhandle.js @@ -23,7 +23,7 @@ const Client = require('_debugger').Client; { const client = new Client(); - client._addHandle({handle: 'not a number'}); + client._addHandle({ handle: 'not a number' }); assert.deepStrictEqual(client.handles, {}); }