I’m trying to debug my mocha tests in VS Code using a launch.json, but this error shows up:
ReferenceError: before is not defined
I also found that I get these errors when I move around and comment out sections of code:
ReferenceError: describe is not defined
ReferenceError: it is not defined
The before, it, and describe are mocha functions. I checked that mocha is being launched and it is. The debugger works fine but once it gets to a mocha function it throws an error.
Here’s my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/**/*.test.js" <-- minor change from default config
],
"internalConsoleOptions": "openOnSessionStart",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/mocha.js", // <-- mocha
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
}
]
}
This is the default configuration for mocha that VS Code automatically generates.