Can't add remote Node Interpreter for mocha in WebStorm - node.js

I am running my code inside a vagrant machine. In WebStorm I can specify in the run configurations to use the vagrant nodejs interpretor:
Now I need to do the same for my mocha tests, however I am unable to add a Remote Node Interpreter in my Mocha run configurations:
Does anybody have an idea how to fix that?

AFAIK that is not currently possible.
https://youtrack.jetbrains.com/issue/WEB-22179 -- watch this ticket (star/vote/comment) to get notified on any progress.

Related

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

Mocha test that runs locally won't run on Jenkins (environment issue)

I'm currently trying to implement CI with Jenkins for an emberjs node project that uses mocha for unit testing. I'm running Jenkins on an Amazon EC2 server.
When I run mocha locally (both on my desktop, AND on the ec2 server) I get this:
./node_modules/mocha/bin/mocha
Initializing server on port 8090
Unit Test for /test
test API call incoming
key res value is: test!
✓ gives a json object with res: test!
1 passing (35ms)
However, when I have jenkins set up to run this same command:
01:44:46 + ./node_modules/mocha/bin/mocha
01:44:46
01:44:46 /var/lib/jenkins/workspace/Rekindle2_Node/server/routes/test/getTest.js:4
01:44:46 const getTest = (req, res) => {
01:44:46 ^
01:44:46 SyntaxError: Unexpected token >
etc
I've double checked, the package.json has everything I need, and I know that I don't have anything globally installed that changes things (as I managed to git clone, npm install, and run mocha from the ec2 instance). All I know is that jenkins sometimes can have issues with consuming environment variables from the server it's running on? Does anyone know what the issue I'm encountering could be? I've tried uninstalling and reinstalling node as well, it could be that Jenkins is looking at an older installation of node while the ec2 is not. Is there any way to tell this? How do I look at the environment variables of a specific build?
That looks like Jenkins is using an older version of node.js. To confirm this I would add logging to your Jenkins job. node --version will print the version of node.js that Jenkins is aware of. Also if you are interested in the environment there is a view in the Jenkins web ui to show the environment from a particular build. Or you can add env as a line in your Jenkins build script to print out the current environment variables. If it turns out to be a node.js version issue, I would look into using a plugin to manage your nodejs versions: node.js Jenkins plugin

Debugging node app in WebStorm when run from gulp

I am using webstorm 10.0.2 and have used the bangular yeoman template to generate a project. I can run the gulp commands via the gulp window, and I can set a breakpoint in the gulpfile.js and it will hit it, but I can't seem to get it to hit a breakpoint in my server.js
It looks to me like the gulp file is launching another instance of node and thus when you do "debug" from webstorm you are just debugging the gulp.
I also tried with another project using yo hottowel but get the same thing - I am unable to debug the actual application through webstorm.
Can anybody tell me how to configure webstorm so that I can debug the actual server side node code but still use the gulp build tool?
I contacted JetBrains support back in May 2015 and their response was:
It seems this cannot be done quickly. In short, the problem is that serve-dev task starts new process (nodemon) that takes app.js
There is no workaround how to debug such spawned processes right now. We would really appreciate if you'll submit a feature request about it in our YouTrack: https://youtrack.jetbrains.com/issues/WEB
The only way you can try to avoid it - try to create a separate task that will run app.js directly without nodemon process and debug this task instead.
It seems the best option is to use https://www.npmjs.com/package/gulp-node-inspector

Issue with Node-based Cordova Hook

I'm playing around with the Cordova hooks capabilities and I'm trying to test using a node application as a hook. In this article: http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/ it references running node applications, so I know it's possible.
I've created a simple node application that I'm using to test the before prepare and after prepare process:
#! /usr/bin/env node
console.log("this is a node module");
When I run my prepare, I get the following error:
C:\Users\jwargo\dev\lunchmenu>cordova prepare
The system cannot find the path specified.
Hook failed with error code 1: C:\Users\jwargo\dev\lunchmenu\hooks\before_prepare\test.js
I can't find any information anywhere about what an error code of 1 means here.
I've tested the node code and it runs fine with "node test.js" and when I execute test.js from the command line Windows simply launches my default editor.
So, can anyone tell me what I'm doing wrong or what I need to do to be able to execute a node application as a hook with the Cordova CLI?
Figured it out with some help from the Cordova dev team. The space in my shebang was causing the problem. I removed it and the problem went away.

Node.js server debuging with WebStorm (grunt)

I'm using grunt to launch my server with livereload and other tasks.
I've followed this and this post to run my grunt tasks.
It's working but I can't debug properly (when I set some breakpoints, there aren't hit)
When I launch the script, here is what I got:
As you can see the debugger appears in a 2nd tab, but it's not doing anything. (even if it says it's connected successfully).
To debug my app I've to stop this 2nd tab, and run a remote debugger... Anyway to fix this?
Additional info: The server is run in another process. If I run it in the same process as grunt, there are no issues.
What Node.js version do you use? In 0.10.x the child process occupies the same port as a master process, so debugging won't work by default. Related ticket: https://github.com/joyent/node/issues/5318. Can you check if it works for you using Node.js ersion >= 0.11.4? Also, what Grunt tasks are being used?
As mentioned by lena, the issue seems to be fixed in WebStorm 8.

Resources