Debug setup for Hapi Lab test framework
I am using Hapi Lab test framework (https://github.com/hapijs/lab) instead of Mocha. I am trying to create a test setup so that I can put breakpoints into the code while running the tests. How can I do that?
I had asked Hapi community and this is the response I get https://github.com/hapijs/discuss/issues/370
Following on that response, I created a run/debug configuration as follows
Node.js template
Name: Lab
Node interpreter: /usr/local/bin/node
JavaScript file: node_modules/lab/bin/lab
With this configuration set, here are my observations (none successful so far)
1. Right click on the editor tab of the test code, select "Debug <filename>", I get the following error
Error running <filename>: Not found node_modules/lab/bin/_mocha
2. Right click on the test filename in the project browser and select "Debug <filename>, same error as above.
3. From the Run menu, choose "Debug Lab", it tries to debug some other file with the same name but in a different directory.
How can I get a debug configuration working with Lab?
Please sign in to leave a comment.
Debugging works for me when using similar configuration:
when choosing Debug in file right-click menu, you are running `node <filename>.js`, which is clearly not the right way to run hapi lab tests
You results are different from mine. I am on Mac. Here's the tar'ed project folder. http://wikisend.com/download/472500/i.tar
From the project folder, I can run the following just fine.
But when I debug it from the PHPStorm 2016.2 debug button, I get
I can't download the file unfortunately:
Access to the web page was blocked.
http://w1.wikisend.com/node-fs/download/91b63d430cbc501f3ae96009527f036c/i.tar
But from the stack trace it seems that your project doesn't contain 'test' directory... By default, unless the test file/folder is passed explicitly, lab loads all the '*.js' files inside the local 'test' directory and executes the tests found. In terminal, you pass a spec file to lab:
but, when running from WebStorm, you don't pass any arguments to lab, thus the execution fails because test folder is not found...
I'd suggest you to read the docs available at https://github.com/hapijs/lab first
You are right the "Lab" configuration doesn't provide the filename to debug. If there were 100 test files, would I need to create 100 separate setups e.g. "Lab file1", "Lab file2" etc.?
Shouldn't Webstorm provide the filename to debug?
>You are right the "Lab" configuration doesn't provide the filename to debug.
you have to modify it accordingly - by adding desired file name to 'Application parameters' field
>If there were 100 test files, would I need to create 100 separate setups e.g. "Lab file1", "Lab file2" etc.?
if you need running all them one-by-one - yes. Otherwise you just can list all them as application parameters, or pass the directory they are located in:
>Shouldn't Webstorm provide the filename to debug?
Definitely not. WebStorm can't know what parameters you'd like to pass to your application. Seems you don't know it yourself - so how can the IDE guess it?
While you say that IDE should not provide the filename for the test, but it does exactly that for mocha.
package.json
{"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.0"
}
}
test.js
Select "Debug 'test.js'" from Run menu as follows
A console window opens showing the following command being run
Note the last parameter of the command - it's the filename of the test file.
While mocha debug runs put filenames in the debug command, shouldn't the Lab debug run do the same?
That's because PHPStorm provides special support for Mocha (and has a special configuration for it). And it doesn't provide any support for Hapi lab
This image shows how I got it to work based on the discussion above: