【问题标题】:Running Mocha tests compiled with Babel in Visual Studio Code在 Visual Studio Code 中运行使用 Babel 编译的 Mocha 测试
【发布时间】:2015-10-09 19:55:25
【问题描述】:

我在 Mocha 测试中使用 Babel。要在终端中运行测试,我使用以下命令:

mocha --debug --compilers js:babel/register

然后我可以使用 VS Code“附加”调试选项附加到测试过程。我可以设置断点并停止,但是因为原始代码在 ES6 中,VS Code 对行号等感到困惑。

有没有办法让 VS Code 使用这个设置?

我的“附加”配置:

    {
        "name": "Attach",
        "type": "node",
        // TCP/IP address. Default is "localhost".
        "address": "localhost",
        // Port to attach to.
        "port": 5858,
        "sourceMaps": false
    }

"sourceMaps": true 没有任何区别

我正在尝试运行测试的项目是开源。 GitHub 仓库:https://github.com/mohsen1/yawn-yaml/

【问题讨论】:

    标签: testing mocha.js babeljs visual-studio-code


    【解决方案1】:

    我使用这个配置在本地使用 babel 运行 mocha:

    "configurations": [
        {
            "name": "Debug Mocha",
            "type": "node",
            "program": "./node_modules/.bin/_mocha",
            "stopOnEntry": false,
            "args": ["--compilers", "js:babel-register"],
            "cwd": ".",
            "runtimeExecutable": null,
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": true,
            "outDir": null
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858
        }
    ]
    

    使用 _mocha 可执行文件,因为节点已被代码调用。另外,请确保您已将 sourceMaps 设置为 true

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 2020-12-22
      • 1970-01-01
      • 2017-08-18
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多