From 7b4cc58b70a7679a7ce0c244b6d083438b8d6c22 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 29 Jan 2023 23:46:36 +0200 Subject: [PATCH] inspector: allow opening inspector when `NODE_V8_COVERAGE` is set PR-URL: https://github.com/nodejs/node/pull/46113 Fixes: https://github.com/nodejs/node/issues/46110 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell --- src/inspector_js_api.cc | 2 +- test/fixtures/inspector-open.js | 14 +++++++++++++ test/parallel/test-inspector-open-coverage.js | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/inspector-open.js create mode 100644 test/parallel/test-inspector-open-coverage.js diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 3595536c785ed7..1602faf1bd66fa 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -273,7 +273,7 @@ static void RegisterAsyncHookWrapper(const FunctionCallbackInfo& args) { void IsEnabled(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - args.GetReturnValue().Set(InspectorEnabled(env)); + args.GetReturnValue().Set(env->inspector_agent()->IsListening()); } void Open(const FunctionCallbackInfo& args) { diff --git a/test/fixtures/inspector-open.js b/test/fixtures/inspector-open.js new file mode 100644 index 00000000000000..715687fe0e1e28 --- /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 00000000000000..259049c36822ab --- /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);