Skip to main content

How to Debug a Test

Problem

In the course of developing tests, any developer will sooner or later encounter errors that are hard to detect through normal code review. At such moments, it's necessary to use software tools to understand where the error occurred, or why the test is behaving differently than expected.

Let's explore the options available to a Testplane test developer.

Solution 1: --inspect or --inspect-brk option

To see how a test is executed step by step, Testplane has a debug mode. This mode relies on the V8 inspector integration with Node.js.

About V8 Inspector Integration with Node.js

The integration with the V8 inspector allows connecting Chrome DevTools to a Node.js instance for debugging and profiling. This uses the Chrome DevTools protocol.

The V8 inspector can be enabled by passing the --inspect option when starting a Node.js application. You can also specify a custom port with this option; for example, --inspect=9222 will accept DevTools connections on port 9222.

To stop the code execution at the first line of the application, use the --inspect-brk option instead of --inspect.

$ node --inspect index.js
Debugger listening on ws://127.0.0.1:9229/dc9010dd-f8b8-4ac5-a510-c1a114ec7d29
For help, see: https://nodejs.org/en/docs/inspector

In the example above, the UUID dc9010dd-f8b8-4ac5-a510-c1a114ec7d29 at the end of the URL is generated "on the fly," and varies in different debugging sessions.

If the Chrome browser is older than 66.0.3345.0, use inspector.html instead of js_app.html in the above URL.

Chrome DevTools does not yet support debugging for worker threads. To debug them, you can use ndb.

To run a test in this mode, use the --inspect option. If you want the debugger to stop at the first line of code, use the --inspect-brk option.

Example:

testplane path/to/mytest.js --inspect
info

In debug mode, only one worker process is started, and all tests are run in it. Use this mode with the parameter sessionsPerBrowser=1 to debug tests one at a time.

Keywords

  • --inspect
  • --inspect-brk