在Visual Studio Code中运行用Babel编译的Mocha测试

在Visual Studio Code中运行用Babel编译的Mocha测试

问题描述:

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

I am using Babel in my Mocha tests. To run the test in terminal I use following command:

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

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

Then I can use VS Code "Attach" debugging option to attach to the test process. I can set breakpoints and it stops, but because original code is in ES6 VS Code gets confused about line numbers and such.

无论如何,是否可以使VS Code在此设置下正常工作?

Is there anyway to make VS Code work with this setup?

我的附加"配置:

    {
        "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/

The project I'm trying to run the test is open source. GitHub repo: https://github.com/mohsen1/yawn-yaml/

我使用以下配置在本地使用babel运行mocha:

I got mocha running with babel locally using this config:

"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 可执行文件,因为该节点已被Code调用.另外,请确保已将 sourceMaps 设置为 true .

Which uses the _mocha executable since node is already invoked by Code. Also, make sure you have sourceMaps set to true.