Enable step-by-step debugging¶
This section covers how to enable debugging for a Node.js application that is started with the Test Launcher.
The main reason why you would want to enable debugging of your tests is that by setting pauses (breakpoints) you will be able to follow your test execution step-by-step and see how the device reacts to each command.
The Test Launcher supports both
--inspect=[port]
and --inspect-brk=[port]
Node.js debugging options.
Debugging in Chrome developer tools¶
-
In Chrome browser open
chrome://inspect/#devices
page. Make sure that Discover network targets checkbox is checked. -
Press Configure... button next to Discover network targets option to set up ports that Chrome Developer Tools should be listening to.
-
Start your Node.js script with Suitest Test Launcher. Make sure you pass either
--inspect=[port]
or--inspect-brk=[port]
parameter, where[port]
is one of the ports, configured in previous step. For examplesuitest run node --inspect-brk=9121 ./node_modules/mocha/bin/_mocha --no-timeouts --exit
-
In Chrome you should now see your Node process under Remote Target section. Click inspect to open Chrome Developer Tools attached to your process.
Debugging in JetBrains IDE (WebStorm, PhpStorm, IntelliJ IDEA etc.)¶
Create Node.js configuration. Set the following:
-
Working directory to root folder of your project (where your
package.json
file is located) -
JavaScript file to
./node_modules/suitest-js-api/lib/testLauncher/index.js
-
Application parameters to
suitest run node [command]
, where[command]
is a Node.js script you want to debug. For example,suitest run node ./node_modules/mocha/bin/_mocha --no-timeouts --exit
.
Specifying debug port
If you need debugger to be on some exact port, you need to add
--inspect-brk=[some avaliable port]
(it will be used for main Suitest process)
to Node parameters
field and adjust Application parameters
field
to suitest run node --inspect-brk=[desired port] [command]
.
You can launch the built-in IDE debugger by selecting Run > Debug in main menu and selecting newly created configuration in the popup.
Debugging in Visual Studio Code¶
Create Node.js configuration (configurations array in launch.json
debugger configuration file). Fill it in with the following:
{
"type": "node",
"request": "launch",
"name": "Debug node",
"program": "${workspaceFolder}",
"args": [
"run",
"--inspect-brk=[port]",
"[command]"
],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"console": "integratedTerminal"
}
[port]
is any port you'd like debugger to listen to and [command]
is a
Node.js script you want to debug. Then run the newly added configuration
For a more complex [command]
, such as the commands that require spaces to
execute correctly you will have to split the args
members individually. Take
the following example for instance:
"/node_modules/cucumber/bin/cucumbeer-js features/**/*.feature --require build/step-definitions/**/*.js --require build/cucumber/**/*.js"
The configuration would look like this:
{
"type": "node",
"request": "launch",
"name": "Debug node",
"program": "${workspaceFolder}/node_modules/suitest-js-api/lib/testLauncher/index.js",
"args": [
"run",
"--inspect-brk=9121",
"node",
"./node_modules/mocha/bin/_mocha",
"--no-timeouts",
"--exit"
],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"console": "integratedTerminal"
}
Passing Node.js script¶
When debugging, make sure to pass the Node.js script to the Test Launcher and
not a wrapper. For example, on Windows NPM would wrap any executables into CMD
file, so passing node_modules/.bin/[executable]
will cause syntax error.
Instead, reference JavaScript file from the package source. Like so:
suitest run --inspect-brk=9121 ./node_modules/[package]/[path-to]/[executable.js]