Skip to content

Commit e0a0d48

Browse files
committed
test_runner: fix --require with --experimental-loader
1 parent 8b66dc6 commit e0a0d48

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/api/environment.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ NODE_EXTERN std::unique_ptr<InspectorParentHandle> GetInspectorParentHandle(
529529
CHECK_NOT_NULL(env);
530530
if (name == nullptr) name = "";
531531
CHECK_NE(thread_id.id, static_cast<uint64_t>(-1));
532+
if (!env->should_create_inspector()) {
533+
return nullptr;
534+
}
532535
#if HAVE_INSPECTOR
533536
return std::make_unique<InspectorParentHandleImpl>(
534537
env->inspector_agent()->GetParentHandle(thread_id.id, url, name));

test/fixtures/test-runner/esm/bootloader.js

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function resolve(specifier, context, next) {
2+
return next(specifier);
3+
}
4+
5+
export function load(href, context, next) {
6+
return next(href);
7+
}

test/parallel/test-runner-cli.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,20 @@ const testFixtures = fixtures.path('test-runner');
185185
assert.match(stdout, /# tests 1/);
186186
assert.match(stdout, /# pass 1/);
187187
}
188+
189+
{
190+
// Use test with --loader and --require.
191+
// This case is common since vscode uses --require to load the debugger.
192+
const args = ['--no-warnings',
193+
'--loader', join(testFixtures, 'esm', 'loader.mjs'),
194+
'--test', join(testFixtures, 'index.test.js')];
195+
const child = spawnSync(process.execPath, args, {
196+
env: { NODE_OPTIONS: `--require="${join(testFixtures, 'esm', 'bootloader.js')}"` }
197+
});
198+
199+
assert.strictEqual(child.stderr.toString(), '');
200+
assert.strictEqual(child.status, 0);
201+
assert.strictEqual(child.signal, null);
202+
const stdout = child.stdout.toString();
203+
assert.match(stdout, /ok 1 - this should pass/);
204+
}

0 commit comments

Comments
 (0)