How to debug on console with Hapi.js Lab test framework? - node.js

Mocha has the option to run tests with mocha debug, just like node debug, allowing debug within a REPL console.
How can I do REPL debug with Hapi Lab?

I just have to run node debug node_modules/.bin/lab *.js, just like #matt-harrison said.
The only tip is: Do not use coverage when debugging, since the coverage will change the original code and make debug difficult.

Related

testcafe execution via intelliJ run action

I have my testcafe test which is running well via terminal with
testcafe chrome jira-web-front\src\test\script\testcafe
I would like to be able to run it inside intelliJ js editor by clicking on the play button:
When I execute my test by clicking on the green play button I have:
I have some jest tests also in my project.
I tried to install intelliJ testcafe plugin but it didn't help.
Any idea about this?
Thanks
The logic currently used by JavaScript support plugin for detecting what test runner is available for a given test file is based on dependencies declarations in package.json nearest to this file: it looks for known test runners listed there and tries to run the most suitable one. As IDEA
doesn't provide any support for TestCafe (https://youtrack.jetbrains.com/issue/WEB-30315), you can't expect it to run TestCafe from a gutter; it runs your tests with jest because you have it in your dependencies list.
To run test using the run configuration provided by testcafe plugin, you need right-clicking the test in editor:
This plugin doesn't support running tests from gutter, neither it supports debugging.
Note that you can use VS Code recipes to debug TestCafe in IDEA. Namely, you need Node.js Run configuration like the following:
where JavaScript file: is set to a path to your locally installed testcafe module, e.g. node_modules\testcafe\bin\testcafe.js, and Application parameters: are testcafe cli args, like
chrome myTestFile.js

How to debug Protractor e2e tests with ndb?

I have recently discovered the magic of debugging Node applications with ndb. (You should really check it out, if you've never seen it.)
For our non-e2e integration tests (which use jasmine) I was easily able to debug the test code simply by substituting ndb for node.
ndb node_modules/jasmine/bin/jasmine.js --config=jasmine.json
When I do the same for protractor, the debugger comes up, but the tests don't begin. For example, the following fails:
ndb node_modules/protractor/bin/protractor protractor.conf.ts --suite smoke
Any clues? (I have a suspicion that it has to do with the Typescript transpilation that happens, but I have no evidence hard evidence.)
I solved my own problem by more trial-and-error. I do not understand why this makes a difference, but the following variation on the ndb command worked:
ndb node node_modules/protractor/bin/protractor protractor.conf.ts --suite smoke
According to ndb --help, ndb provides several variations on how to kick off debug sessions. Like I said, I'm not sure why the ndb node flavor worked while straight ndb failed.

Nuclide debugger with node and babel?

I've been trying to use Nuclide/Atom to launch and debug a unit test that uses Babel and ES6+ code. The launch config looks like this:
Node runs the unit test as if I had run it from the command-line, and does not stop at my breakpoints. If I use the same invocation at the command-line with --inspect-brk I can debug correctly (with sourcemaps) from the chrome-devtools url in Chrome. Is there a way to make this work? I can't really "attach" since the unit tests are, and should be, a straight-shot script execution.
Nuclide currently does not support the new v8 Inspector protocol for debugging. You will need to use --debug flag to debug with Nuclide. Note, however, that the old debugger protocol has been removed from Node.js starting with Node.js 8.0.
PS. You can attach to a running Node.js process with Nuclide debugger just fine - just start your tests with node --debug --debug-brk ... and then attach the debugger from Nuclide. The test process will be stopped at first line, allowing you to resume execution at your own convenience.

Debugging Serverless Framework invoke local function

I am trying to debug sls invoke local.
My setup:
However I keep getting:
/Users/nikos/.nvm/versions/node/v6.9.1/bin/node --debug-brk=63417 --expose_debug_as=v8debug /Users/nikos/.nvm/versions/node/v6.9.1/bin/serverless invoke local -f createTodo
Debugger listening on [::]:63417
Process finished with exit code 130 (interrupted by signal 2: SIGINT)
OK, I've figured out how to do this with real Chrome Devtools with the excellent node --inspect. This is much better than node inspector because it uses the latest built in chrome devtools. (more info on node inspect)
node --debug-brk --inspect $(which serverless) invoke local -f myfunctionname
I ran that but my function wasn't loaded yet (probably some lazy loading in the serverless code). So I added a debugger to the top line of my function and everything seems to be working great.
In my case I also needed some test data, so I passed that through like this.
node --debug-brk --inspect $(which serverless) invoke local -f postprocess -d '{"Records":[{"eventVersion":"2.0","eventSource":"aws:s3","awsRegion":"us-east-1","eventTime":"2017-06-17T05:08:29.598Z","eventName":"ObjectCreated:Put","userIdentity":{"principalId":"ALS78N87ZDYNW"},"requestParameters":{"sourceIPAddress":"52.119.114.78"},"responseElements":{"x-amz-request-id":"2EB4FAD5892EC247","x-amz-id-2":"nVLasIYsWvWm7xwONiTB6z7L8oXKkvPOb9FntOYoG/kKS+PuWwbMJ1xM7n/C1X3NJh5FUCj4aEM="},"s3":{"s3SchemaVersion":"1.0","configurationId":"3c3b2a71-b639-4116-b246-08dcacd0c7d6","bucket":{"name":"simmer-uploads-test","ownerIdentity":{"principalId":"ALS78N87ZDYNW"},"arn":"arn:aws:s3:::simmer-uploads-test"},"object":{"key":"example+%285%29.zip","size":4757597,"eTag":"9aa90579ee4e8152e6dfa60258754a83","sequencer":"005944B94AD9307261"}}}]}'
I am working on a Mac, and I heard there might be some problems with $(which serverless) on windows. But someone give it a shot and let me know.
I was able to setup my PHPStorm debugger configuration in a way that now I can step through my functions locally (using serverless-offline plugin).
I am triggering functions via http requests using Postman.
See below steps to achieve this:
1.
2.
3.
4.
I've gotten this to work in IntelliJ, so it should work in Webstorm too. You will need the serverless-offline plugin (https://github.com/dherault/serverless-offline)
In your Run Configuration, change your Application parameters to:
offline -s dev
and add the environment variable SLS_DEBUG=*
serverless-offline will start a server that the IntelliJ Node debugger can hook into.
Use this, it emulates lambda and serverless:
https://github.com/dherault/serverless-offline#debug-process

How do you set a breakpoint with node.js jasmine?

Ok, naive question here, but I am somewhat new to nodejs. I am writing a test script using jasmine. There seems to be a bug in my code, so I put "debugger" in one of the lines and jasmine is not stopping for some reason. I know it's getting to the code too, because I put a console.print command and it displays that line.
Is there something incredibly simple that I'm missing? Can't I set a breakpoint in the javascript code and get into a REPL somehow?
You probably run your Jasmine Tests like this:
$ jasmine myTest.js
Or like this:
$ ./node_modules/jasmine/bin/jasmine.js myTest.js
If you want to test node application you have many options, and as you know, jasmine is nodejs code, so you can run it in debug mode, and will run your test, so if you have debugger; in your code it will stop there.
Here are 3 simple ways to debug nodejs applications. Node.js Debug Options
You can use the first one, the build in debugger in nodejs.
Run this command:
$ node debug jasmine myTest.js
Or
$ node debug ./node_modules/jasmine/bin/jasmine.js myTest.js
Then you can press C button + Enter to continue to your debugger; brackpoint in your code...

Resources