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

Breakpoints in VS Code #157

Closed
somebeaver opened this issue Jun 16, 2020 · 2 comments
Closed

Breakpoints in VS Code #157

somebeaver opened this issue Jun 16, 2020 · 2 comments

Comments

@somebeaver
Copy link

somebeaver commented Jun 16, 2020

I'm wondering if it's possible to set breakpoints in the VS Code debugger with electron-mocha.

This is my config in my project's /.vscode/launch.js file

{
  "name": "Mocha Current File",
  "type": "node",
  "request": "launch",
  "program": "${workspaceFolder}/node_modules/electron-mocha/bin/electron-mocha",
  "args": [
    "--require",
    "test/rootHooks.js",
    "--no-timeouts",
    "--colors",
    "${file}"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
}

If I switch "program" to "${workspaceFolder}/node_modules/mocha/bin/_mocha", breakpoints work as expected.

I found this issue, and I tried to add the --debug arg, but it doesn't work. I'm not sure if this is a configuration issue or if breakpoints are not supported.

Thank you

@inukshuk
Copy link
Collaborator

I'm not using VS Code myself, so I can't comment on that specifically, but you can definitely use the debugger in electron-mocha.

Since ./bin/electron-mocha is a Node.js script that launches Electron this indirection is probably what throws off the VS Code integration. You could try running Electron directly and pointing it to electron-mocha's entry point. That is, as "program" put in the path to the Electron executable you want to run and as the first argument add ${workspaceFolder}/node_modules/electron-mocha/lib/main.js; also add --inspect to the argument list. Does that work?

@somebeaver
Copy link
Author

Thanks for the reply. I tried changing it to this:

{
  "name": "Electron-Mocha: debug current file",
  "type": "node",
  "request": "launch",
  "program": "${workspaceFolder}/node_modules/.bin/electron",
  "args": [
    "${workspaceFolder}/node_modules/electron-mocha/lib/main.js",
    "--inspect",
    "${file}"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
}

I'm pretty sure that's how you meant it. I'm kinda new to the Electron ecosystem, so if you had something else in mind please correct me.

The tests work, but the breakpoints still don't hit unfortunately. Doing it this way also seems to create 2 debuggers according to the output messages.

This is the test I'm testing with:

const assert = require('assert')

describe('Test', () => {
  it('will pass', () => {
    assert(true, true)
  })
})

With a breakpoint on the assert() line. The breakpoint hits when using the original mocha, but not with electron-mocha with the same configs. I simplified the original mocha config to:

{
  "name": "Original Mocha: debug current file",
  "type": "node",
  "request": "launch",
  "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
  "args": [
    "${file}"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen"
}

But no matter how I try to configure it with electron-mocha, I just can't get the VS Code debugger to work like it does with the original mocha

I also tried switching to a global electron-mocha install, but no luck. I suppose I'll wait and hope that someone else who uses VS Code can make it work.

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

2 participants