Cannot seem to properly debug mocha-webpack in VSCode
dbschwartz opened this issue · 3 comments
Hello,
I recently tried to debug mocha-webpack using the suggested recipe but it seems that even though I put in debuger in the editor the stack trace only dives into the mocha library itself but not the actual tests or my source code. I think this problem could possibly stem from the fact that the mocha-webpack source maps are generated in memory and are not accessible to VSCode through the outFiles
variable. Any help would be greatly appreciated.
Thank you!
Hey @dbschwartz did you ever find a solution? I'm having the same problem.
I've gotten close with the following configuration:
Reproduce:
launch.json
{
"type": "node",
"request": "launch",
"name": "Debug All Tests",
"protocol": "inspector",
"useWSL": true,
"sourceMaps": true,
"stopOnEntry": true,
"runtimeExecutable": "npm",
"port": 9229,
"runtimeArgs": [
"run",
"test:debug"
]
}
package.json:
{
"scripts": {
"test:debug": "node --inspect ./node_modules/.bin/mocha-webpack --webpack-config ./webpack.test-config.babel.js \"src/**/*[-.]test.js\""
},
"dependencies": {
"mocha-webpack": "^2.0.0-beta.0"
}
}
switching the flag from --inspect
to --inspect-brk
causes both vscode and chrome debugger to pause on the first line of mocha-webpack, rather than the first line of usercode. When I change the script to: mocha-webpack --inspect ...
the debugger fails to work at all.
I'm fairly certain this is a problem with mocha-webpack and webpack 4. See more info on this project's maintenance here 289
@dbschwartz here's the launch.json
that's working for me:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach Debugger",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": true,
"sourceMaps": true,
"outFiles": [],
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Run mocha-webpack",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha-webpack/bin/mocha-webpack",
"args": [
"--debug-brk", "5858",
"--timeout", "120000",
"--webpack-config", "${workspaceRoot}/build/webpack.config.test.js",
"--require", "test/setup.js",
"${file}"
],
"stopOnEntry": false,
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
],
"env": { "NODE_ENV": "test"},
"console": "integratedTerminal",
"outFiles": []
}
]
}
@natchiketa what version of mocha-webpack are you using?
On the current 1.1.0 I get a "Unknown argument: debug-brk" error.