From e0a0d480e18356ff82eeb3fa54f7e985e0a5cd77 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Thu, 27 Apr 2023 23:50:24 +0300 Subject: [PATCH] test_runner: fix --require with --experimental-loader --- src/api/environment.cc | 3 +++ test/fixtures/test-runner/esm/bootloader.js | 0 test/fixtures/test-runner/esm/loader.mjs | 7 +++++++ test/parallel/test-runner-cli.js | 17 +++++++++++++++++ 4 files changed, 27 insertions(+) create mode 100644 test/fixtures/test-runner/esm/bootloader.js create mode 100644 test/fixtures/test-runner/esm/loader.mjs diff --git a/src/api/environment.cc b/src/api/environment.cc index cfc4426e1aa6c0..06dada9a47214c 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -529,6 +529,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/fixtures/test-runner/esm/bootloader.js b/test/fixtures/test-runner/esm/bootloader.js new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/test/fixtures/test-runner/esm/loader.mjs b/test/fixtures/test-runner/esm/loader.mjs new file mode 100644 index 00000000000000..b1fea045d39693 --- /dev/null +++ b/test/fixtures/test-runner/esm/loader.mjs @@ -0,0 +1,7 @@ +export function resolve(specifier, context, next) { + return next(specifier); +} + +export function load(href, context, next) { + return next(href); +} \ No newline at end of file diff --git a/test/parallel/test-runner-cli.js b/test/parallel/test-runner-cli.js index 5e913eb6de9e5d..d450581dcb5a9b 100644 --- a/test/parallel/test-runner-cli.js +++ b/test/parallel/test-runner-cli.js @@ -185,3 +185,20 @@ 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', + '--loader', join(testFixtures, 'esm', 'loader.mjs'), + '--test', join(testFixtures, 'index.test.js')]; + const child = spawnSync(process.execPath, args, { + env: { NODE_OPTIONS: `--require="${join(testFixtures, 'esm', 'bootloader.js')}"` } + }); + + 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/); +}