Running Mocha tests compiled with Babel in Visual Studio Code

佐手、 提交于 2020-01-01 02:41:11

问题


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

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

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.

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

My "Attach" config:

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

"sourceMaps": true doesn't make any difference

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


回答1:


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
    }
]

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



来源:https://stackoverflow.com/questions/33046165/running-mocha-tests-compiled-with-babel-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!