From 8398bca842ce19ff5e590980424fb3cf2512cd15 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 30 Apr 2023 02:02:03 +0300 Subject: [PATCH] test_runner: fix --require with --experimental-loader PR-URL: https://github.com/nodejs/node/pull/47751 Reviewed-By: Jacob Smith Reviewed-By: Geoffrey Booth Reviewed-By: Antoine du Hamel --- src/api/environment.cc | 3 +++ test/parallel/test-runner-cli.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/api/environment.cc b/src/api/environment.cc index c3f2fa10a8d89f..22f77160fb1737 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -462,6 +462,9 @@ NODE_EXTERN std::unique_ptr GetInspectorParentHandle( CHECK_NOT_NULL(env); if (name == nullptr) name = ""; CHECK_NE(thread_id.id, static_cast(-1)); + if (!env->should_create_inspector()) { + return nullptr; + } #if HAVE_INSPECTOR return std::make_unique( env->inspector_agent()->GetParentHandle(thread_id.id, url, name)); diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 5e913eb6de9e5d..1af875e7e24def 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -185,3 +185,19 @@ const testFixtures = fixtures.path('test-runner'); assert.match(stdout, /# tests 1/); assert.match(stdout, /# pass 1/); } + +{ + // Use test with --loader and --require. + // This case is common since vscode uses --require to load the debugger. + const args = ['--no-warnings', + '--experimental-loader', 'data:text/javascript,', + '--require', fixtures.path('empty.js'), + '--test', join(testFixtures, 'index.test.js')]; + const child = spawnSync(process.execPath, args); + + assert.strictEqual(child.stderr.toString(), ''); + assert.strictEqual(child.status, 0); + assert.strictEqual(child.signal, null); + const stdout = child.stdout.toString(); + assert.match(stdout, /ok 1 - this should pass/); +}