Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use with VS Code #29

Open
notenoughneon opened this issue Jul 7, 2016 · 9 comments
Open

Use with VS Code #29

notenoughneon opened this issue Jul 7, 2016 · 9 comments

Comments

@notenoughneon
Copy link

I'd like to use Visual Studio Code's debugger with mocha-webpack tests. VS Code can debug mocha tests, but you have to tell it to use "node_modules/mocha/bin/_mocha" and not "mocha".

For mocha-webpack I tried both "node_modules/mocha-webpack/bin/mocha-webpack" and "node_modules/mocha-webpack/bin/_mocha" and it would run the tests but not attach the debugger. Not sure what is going wrong. Possibly related to #19

@zinserjan
Copy link
Owner

I don't use VS Code, but it's perhaps similiar to Intellij's mocha plugin.

The following config works for me. Have a look at devtoolModuleFilenameTemplate, devtoolFallbackModuleFilenameTemplate and devtool.

webpack.config.test.js

module.exports = {
  ....
  output: {
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
  }
  target: 'node',
  devtool: "source-map"
};

Moreover i had to include source-map-support with --require source-map-support/register in my mocha-webpack.opts or as command argument.

@notenoughneon
Copy link
Author

Thanks for the suggestion. The devtool- options fixed VS Code debugging of my manual test build, but Code still doesn't attach to mocha-webpack.

I tried "--require source-map-support/register", but it breaks both mocha and mocha-webpack with the following error:

node_modules/source-map-support/source-map-support.js:411
      var hasStack = (arguments[1] && arguments[1].stack);
                                                  ^
SyntaxError: 

@notenoughneon
Copy link
Author

I managed to fix the source-map-support syntax error by adding the 'node' environment option: evanw/node-source-map-support#137

The VS Code attachment issue remains though.

@correttojs
Copy link

+1
it would be useful to have a --debug-brk option to run mocha in debug mode
The workaround is to compile with webpack, run mocha with --debug-brk and the attach VS Code debugger

@zinserjan
Copy link
Owner

--debug-brk option isn't necessary. Mocha have this option only cause they are spawning another mocha process (see here). mocha-webpack does not spawn another process, so --debug-brk should work without further adjustments.

@doronbrikman
Copy link

Are you manage to run it?
I'm getting an error:

Module parse failed: Unexpected token
You may need an appropriate loader to handle this file type

but it's the same webpack config that I run in the console. what can be the problem here?

@rosieks
Copy link

rosieks commented Apr 20, 2017

Does anybody have any success with that?

@xugao
Copy link

xugao commented Jun 8, 2017

+1, not been able to debug tests in vscode using mocha-webpack. Any updates?

@lpreterite
Copy link

lpreterite commented Nov 22, 2018

I have tried the following code is feasible, but I don't know why.

webpack.config.js

if (process.env.NODE_ENV === "test") {
    //If you would to use breakpoint in vscode, then must be set devtool to "eval" base
    config.devtool = "eval"; 
    config.output = Object.assign(config.output, {
        devtoolModuleFilenameTemplate: "[absolute-resource-path]",
    });
}

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Mocha-webpack Tests",
        "program": "${workspaceFolder}/node_modules/mocha-webpack/bin/mocha-webpack",
        "args": [
            "--full-trace",
            "--timeout",
            "999999",
            "--colors",
            "tests/**/*.js"
        ],
        "sourceMaps": true,
        "env": {
            "NODE_ENV": "test"
        },
        "internalConsoleOptions": "openOnSessionStart"
    }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants