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

Moh*_*sen 9 testing mocha.js babeljs visual-studio-code

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

mocha --debug --compilers js:babel/register
Run Code Online (Sandbox Code Playgroud)

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

反正有没有让VS Code与这个设置一起工作?

我的"附加"配置:

    {
        "name": "Attach",
        "type": "node",
        // TCP/IP address. Default is "localhost".
        "address": "localhost",
        // Port to attach to.
        "port": 5858,
        "sourceMaps": false
    }
Run Code Online (Sandbox Code Playgroud)

"sourceMaps": true 没有任何区别

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

Pau*_*yng 3

我使用以下配置在本地使用 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
    }
]
Run Code Online (Sandbox Code Playgroud)

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