vscode“run test”无反应的根本原因是本地 jest 未正确安装或配置。需确保:①本地安装 jest 和 @types/jest;②存在有效 jest.config.js 或 package.json 的 jest 字段;③testmatch 正确匹配测试文件路径;④tsconfig.json 启用 sourcemap 和 inlinesources;⑤launch.json 配置 --runinband 等参数。

VSCode 里点“Run Test”没反应,先确认 npx jest 能否在终端跑通
这是所有问题的起点。VSCode 不运行 Jest,它只是调用你项目里的 npx jest(或 yarn jest、pnpx jest)。如果终端里执行 npx jest --version 报错 command not found 或 Cannot find module 'jest',那插件根本不会启动。
- 必须本地安装:
npm install --save-dev jest @types/jest(全局npm install -g jest无效) - pnpm 项目用
pnpx jest --version,yarn 项目用yarn jest --version - 检查项目根目录是否有
jest.config.js或package.json中含"jest"字段——没有配置文件,插件连扫描规则都读不到
testMatch 配不对,VSCode 就“看不见”你的测试文件
Orta 插件默认只认 **/__tests__/**/*.[jt]s?(x) 和 **/?(*.)+(spec|test).[jt]s?(x)。如果你的测试文件叫 Button.unit.tsx 或放在 src/tests/ 下,它直接忽略,右上角按钮压根不出现。
使用一条命令部署ProbeChain Rydberg测试网代理节点。自动注册为Agent(NodeType=1),免gas,支持macOS/Linux/Windows。触发词:/r
- 在
jest.config.js中显式写:testMatch: ['<rootdir>/src/**/*.{test,spec,unit}.{js,jsx,ts,tsx}']</rootdir> - 路径里用
<rootdir></rootdir>,别写./src或src——插件解析时会出错 - 删掉
testRegex字段:它和testMatch冲突,后者优先,前者白配 - 改完必须彻底重启 VSCode(不是重载窗口),否则缓存还在,旧规则继续生效
断点打不中?90% 是 sourceMap + inlineSources 没开全
TS 项目里断点停在空行、__tests__/xxx.js 或 node_modules 里,不是插件坏了,是 source map 没映射回源码。Jest 运行的是编译后的 JS,VSCode 需要完整路径信息才能跳转。
-
tsconfig.json中必须同时设:"sourceMap": true和"inlineSources": true -
jest.config.js的transform必须覆盖.ts和.tsx:'^.+\.tsx?$': 'ts-jest' - 别在
setupFilesAfterEnv里 throw 错误——调试器还没 attach,进程就退出了,断点根本加载不了 - 调试前看 Output → Testing 面板,复制它实际执行的命令(比如
npx jest --runInBand),粘到终端手动跑一遍,确认有没有模块找不到的报错
launch.json 里漏了 --runInBand,断点基本等于摆设
Jest 默认多进程并行执行,而 VSCode 的 Node.js 调试器只能 attach 到主进程。不加 --runInBand,断点要么不触发,要么只在某个子进程里静默停住,你完全感知不到。
-
program字段推荐写成:"${workspaceFolder}/node_modules/.bin/jest"(macOS/Linux)或"${workspaceFolder}/node_modules/jest/bin/jest.js"(Windows) -
args至少包含:"--runInBand";想调试当前文件,再加"--runTestsByPath"和"${file}" - 别混用
runtimeArgs和--inspect-brk——这会让调试器卡在 Jest 入口,徒增一次手动 F5 - 删掉你手动加的
"autoAttachChildProcesses": true:它在--runInBand下无意义,还可能干扰
launch.json 的启动参数、tsconfig.json 的 source map 设置、jest.config.js 的 transform 和 testMatch。少一个,断点就静默失效——它不会报错,只会假装没看见你点的红点。










