Mohsen
Mohsen

Reputation: 65835

Running Mocha tests compiled with Babel in Visual Studio Code

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/

Upvotes: 9

Views: 1164

Answers (1)

Paul Tyng
Paul Tyng

Reputation: 7584

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.

Upvotes: 3

Related Questions