调试

VSCode

要在 VSCode 中调试测试文件,请创建以下启动配置。

  1. {
  2. // 想了解更多的信息, 请访问: https://go.microsoft.com/fwlink/?linkid=830387
  3. "version": "0.2.0",
  4. "configurations": [
  5. {
  6. "type": "pwa-node",
  7. "request": "launch",
  8. "name": "Debug Current Test File",
  9. "autoAttachChildProcesses": true,
  10. "skipFiles": ["<node_internals>/**", "**/node_modules/**"],
  11. "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
  12. "args": ["run", "${relativeFile}"],
  13. "smartStep": true,
  14. "console": "integratedTerminal"
  15. }
  16. ]
  17. }

然后在调试选项卡中确保选择 ‘Debug Current Test File’,然后你可以打开要调试的测试文件并按 F5 开始调试。

IntelliJ IDEA

创建一个 ‘Node.js’ 运行配置。使用以下配置在调试模式下运行所有测试:

配置项 配置值
Working directory /path/to/your-project-root
JavaScript file ./node_modules/vitest/vitest.mjs
Application parameters run —threads false

然后在调试模式下运行此配置。IDE 将在编辑器中设置的 JS/TS 断点处停止。