nodejs / nodejs/node

V8 Inspector is not available in --require in `node --test`

未关闭
#48,467 8 条评论 16 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

inspector test_runner
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

Version

v20.3.0

Platform

Darwin MacBook-Pro-2.local 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64 x86_64

Subsystem

test_runner

What steps will reproduce the bug?
  1. Have a file start-inspect.js containing:
const inspector = require("node:inspector");
inspector.open();
  1. Have some other file.test.js, which can be empty.
  2. Run NODE_OPTIONS="--require ./start-inspect.js" node --test ./hello.test.js
How often does it reproduce? Is there a required condition?

100%

What is the expected behavior? Why is that the expected behavior?

The inspector should open as usual, as if --test was not given in the CLI

What do you see instead?
$ NODE_OPTIONS="--require ./start-inspect.js" node --test ./hello.test.js

node:inspector:181
  open(port, host);
  ^
This Environment was initialized without a V8::Inspector
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js v20.3.0
Additional information

This does not happen if --test is omitted from the command. This causes issues with the VS/Code debugger which uses this mechanism to initiate debugging. I think Jetbrains does the same thing, so Webstorm and friends probably have the same issue, though I have not tested it.

Also, if I try to open the inspector in the test file itself, it works fine, so it seems like there might be some initialization ordering that's different for --test.

Originally reported on https://github.com/microsoft/vscode-js-debug/issues/1727

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先使用 start-inspect.js、file.test.js、NODE_OPTIONS 和 node --test 重现该失败。在运行 --require 时,跟踪 node:inspector 周围的初始化顺序,并将其与在测试文件中打开 inspector 的情况进行比较。为该命令添加覆盖测试,并在 inspector 能够在 --test 下成功打开时认为该 issue 已完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
devtools, testing-qa
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
55/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。