Debug setup for Hapi Lab test framework

I am using Hapi Lab test framework ( 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

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?


Comment actions Permalink

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

Comment actions Permalink

You results are different from mine. I am on Mac. Here's the tar'ed project folder.

From the project folder, I can run the following just fine.

~/d/intellij $ node_modules/lab/bin/lab test.js

1 tests complete
Test duration: 12 ms
No global variable leaks detected

But when I debug it from the PHPStorm 2016.2 debug button, I get

/usr/local/bin/node --debug-brk=50718 --expose_debug_as=v8debug /Users/vagarwal/dev/intellij/node_modules/lab/bin/lab
Debugger listening on [::]:50718
return binding.stat(pathModule._makeLong(path));

Error: ENOENT: no such file or directory, stat 'test'
at Error (native)
at Object.fs.statSync (fs.js:987:18)
at traverse (/Users/vagarwal/dev/intellij/node_modules/lab/lib/cli.js:72:29)
at paths.forEach (/Users/vagarwal/dev/intellij/node_modules/lab/lib/cli.js:102:38)
at Array.forEach (native)
at Object.internals.traverse (/Users/vagarwal/dev/intellij/node_modules/lab/lib/cli.js:100:11)
at (/Users/vagarwal/dev/intellij/node_modules/lab/lib/cli.js:61:31)
at Object.<anonymous> (/Users/vagarwal/dev/intellij/node_modules/lab/bin/lab:5:23)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Timeout.Module.runMain [as _onTimeout] (module.js:590:10)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)

Process finished with exit code 1
Comment actions Permalink

I can't download the file unfortunately:

Access to the web page was blocked.


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:

node_modules/lab/bin/lab test.js

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 first

Comment actions Permalink

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? 

Comment actions Permalink

>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?

Comment actions Permalink

While you say that IDE should not provide the filename for the test, but it does exactly that for mocha.


"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.0"


'use strict';
const expect = require('chai').expect;
describe("Basic HTTP Tests", function() {
it('should pass', function(done) {

Select "Debug 'test.js'" from Run menu as follows

A console window opens showing the following command being run

/usr/local/bin/node --debug-brk=53372 --expose_debug_as=v8debug /Users/vagarwal/dev/intelmocha/node_modules/mocha/bin/_mocha --timeout 0 --ui bdd --reporter /Applications/ /Users/vagarwal/dev/intelmocha/test.js
Debugger listening on [::]:53372

Process finished with exit code 0

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?

Comment actions Permalink

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

Comment actions Permalink

This image shows how I got it to work based on the discussion above:



Please sign in to leave a comment.