question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do you debug your tests?

See original GitHub issue

I’m trying to debug the following simple test. My tests run just fine and pass but I never get an opportunity to debug anything. What exactly is app.client.debug() supposed to do? It doesn’t seem to do anything for me. Am I supposed to connect a debugger externally somehow instead? Here is my test file:

const Application = require('spectron').Application
const path = require('path')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')

let appPath = path.join(__dirname, '..', 'Gistbar-darwin-x64', 'Gistbar.app', 'Contents', 'MacOS', 'Gistbar')

if (process.platform === 'win32') {
  appPath += '.cmd'
}

const app = new Application({
  path: appPath,
})

global.before(function () {
  chai.should()
  chai.use(chaiAsPromised)
})

describe('Base Tests', function () {
  beforeEach(function () {
    return app.start()
  })

  afterEach(function () {
    return app.stop()
  })

  it('opens a window', function () {
    app.client.debug()
    return app.client.waitUntilWindowLoaded()
      .getWindowCount().should.eventually.equal(1)
  })
})

Can anybody shed some light on how to properly debug spectron tests? I think that the documentation around “How to debug tests” could be improved a bit. I wouldn’t mind submitting a PR for “How to debug tests” to the main readme if someone teaches me how first 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
Michenuxcommented, Jul 19, 2018

You can also do:

it('opens a window', function () {
     app.browserWindow.openDevTools();
     return app.client.debug();
  })
2reactions
stepbetacommented, Jul 20, 2017

Using VSCode this is my launch.json entry for testing spectron tests:

{
    "name": "debug E2E Tests",
    "type": "node",
    "request": "launch",
    "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
    "stopOnEntry": false,
    "args": ["test/**/*.e2e.js", "--no-timeouts", "--require", "babel-polyfill", "--compilers", "js:babel-register"],
    "cwd": "${workspaceRoot}",
    "runtimeExecutable": null,
    "env": {}
}

Hope this helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Stepping through and debugging code in Unit tests
UnitTesting, go to 'Test' in the main menu of VS 2010, click submenu 'Debug' -> 'tests in current context'. Right-clicking on the test-code...
Read more >
Debugging Tests - Overview | TestComplete Documentation
Debugging refers to halting the test execution on a certain keyword test operation or script line and then running through the test in...
Read more >
Debugging a Test Script - Micro Focus
To debug a specific test case from the active script, click Run > Testcase. Then select a test a test case from the...
Read more >
3 Easy Ways to Debug Jest Tests - JavaScript in Plain English
1. native node inspect + Chrome DevTools. This way requires first launching the command to run the test in an “inspect mode” and...
Read more >
Debugging Unit Tests - Developer Documentation
Within Eclipse¶ · Go to Run->Debug Configurations · Create a new Debug Configuration. · For me, it worked best using the “Standard Create...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found