diff --git a/lib/inspector.js b/lib/inspector.js index 8c2f649411284bb..84dcd3f5bc965c4 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -168,7 +168,7 @@ class Session extends EventEmitter { * @returns {void} */ function inspectorOpen(port, host, wait) { - if (isEnabled()) { + if (isEnabled() && url()) { throw new ERR_INSPECTOR_ALREADY_ACTIVATED(); } // inspectorOpen() currently does not typecheck its arguments and adding diff --git a/test/fixtures/inspector-open.js b/test/fixtures/inspector-open.js new file mode 100644 index 000000000000000..715687fe0e1e28e --- /dev/null +++ b/test/fixtures/inspector-open.js @@ -0,0 +1,14 @@ +const assert = require('assert'); +const inspector = require('inspector'); + + +assert.strictEqual(inspector.url(), undefined); +inspector.open(0, undefined, false); +assert(inspector.url().startsWith('ws://')); +assert.throws(() => { + inspector.open(0, undefined, false); +}, { + code: 'ERR_INSPECTOR_ALREADY_ACTIVATED' +}); +inspector.close(); +assert.strictEqual(inspector.url(), undefined); diff --git a/test/parallel/test-inspector-open-coverage.js b/test/parallel/test-inspector-open-coverage.js new file mode 100644 index 000000000000000..259049c36822ab7 --- /dev/null +++ b/test/parallel/test-inspector-open-coverage.js @@ -0,0 +1,21 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { spawnSync } = require('child_process'); +const fixtures = require('../common/fixtures'); +const tmpdir = require('../common/tmpdir'); + +common.skipIfInspectorDisabled(); +common.skipIfWorker(); + +tmpdir.refresh(); + + +let output = spawnSync(process.execPath, [fixtures.path('inspector-open.js')]); +assert.strictEqual(output.status, 0); + +output = spawnSync(process.execPath, [fixtures.path('inspector-open.js')], { + env: { ...process.env, NODE_V8_COVERAGE: tmpdir.path }, +}); +assert.strictEqual(output.status, 0);