Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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/

like image 793
Mohsen Avatar asked Oct 09 '15 19:10

Mohsen


1 Answers

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.

like image 138
Paul Tyng Avatar answered Nov 02 '22 15:11

Paul Tyng