【问题标题】:VSCode How do I debug with es6 mocha unit tests and jsx filesVSCode 如何使用 es6 mocha 单元测试和 jsx 文件进行调试
【发布时间】:2017-01-09 22:00:55
【问题描述】:

我设法达到了断点,但我遇到了一些问题。

  • 代码在es5中,无法调试
  • 它只使用 .js 到达断点。我需要它来处理 .jsx 文件。
  • Mocha.opts 似乎根本无法解决这个问题。我尝试添加 --compilers jsx:babel-register 并将 .js 重命名为 .jsx 并且断点不再被命中。

Mocha 选项似乎完全停止了它的工作:

--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": { }
    }
  ]
}

【问题讨论】:

    标签: javascript reactjs mocha.js visual-studio-code


    【解决方案1】:

    原来这是节点调试器的一个错误。我通过更改解决了所有问题:

    "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 的 .babelrc 文件。这是我的 .babelrc 文件,例如:

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

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

    【讨论】:

    • 看起来像当前版本的 vscode 你使用 "type" : "node" 然后添加 "protocol": "inspector"。但这个答案让我调试 - 谢谢!
    • "retainLines": true 是帮助我的信息
    猜你喜欢
    • 1970-01-01
    • 2016-06-27
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多