繁体   English   中英

VSCode如何使用es6 mocha单元测试和jsx文件进行调试

[英]VSCode How do I debug with es6 mocha unit tests and jsx files

我设法打破了我的断点,但我遇到了一些问题。

  • 代码在es5中,无法调试
  • 它只用.js命中断点。 我需要它用.jsx文件命中。
  • Mocha.opts似乎根本不起作用。 我尝试添加--compilers jsx:babel-register并从.js重命名为.jsx,断点就不再受到攻击了。

似乎阻止它完全运行的摩卡选项:

--require babel-register
--require test/util/dom.js
--require expect
--compilers jsx:babel-register

Launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "request": "launch",
      "name": "Debug Mocha Test",
      "type": "node",
      "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
      "args": [
        "test/**/*.spec.js", //I need to get this working with .jsx files
        "--require", "babel-register"
        ],
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": null,
      "env": { }
    }
  ]
}

事实证明这是节点调试器的一个错误。 我通过更改修复了所有问题:

"type": "node""type": "node2"

Launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "request": "launch",
      "name": "Debug Mocha Test",
      "type": "node2",
      "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
      "args": [
        "test/**/*.spec.jsx",
        "--colors", "--no-timeouts"
        ],
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": null,
      "env": { }
    }
  ]
}

mocha.opts:

--require babel-register
--require test/util/dom.js
--require expect
--compilers jsx:babel-register

答案取自weinand

你还需要一个带有"retainLines": true root应用程序中的.babelrc文件"retainLines": true 这是我的.babelrc文件,例如:

{
    "presets": [
        "es2015",
        "stage-2",
        "react"
    ],
    "plugins": [
        "transform-es2015-modules-umd"
    ],
        "retainLines": true
}

如果您bad option: --inspect=... ,请尝试安装较新版本的节点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM