Pressing play on my grunt task works, but Debugging as a address conflict
I have a set of grunt tasks, which start a web server and a set of jasmine testcases via protractor + Selenium...
connect: {
options: {
port: 9000,
hostname: 'localhost'
},
livereload: {
options: {
livereload: 35729,
open: true,
base: ['www']
}
},
test: {
options: {
base: ['www']
}
}
}
});
...
grunt.registerTask('e2e-test', ['connect:test', 'protractor:e2e', 'watch:protractor']);
The problem is, when I select to run the grunt test in debug mode.. I'm getting an error as if it's already running
/usr/local/bin/node --debug-brk=57906 /usr/local/lib/node_modules/grunt-cli/bin/grunt --gruntfile /Users/project/Gruntfile.js e2e-test
Debugger listening on port 57906
Running "connect:test" (connect) task
Started connect web server on http://localhost:9000
Running "protractor:e2e" (protractor) task
Error: listen EADDRINUSE
at exports._errnoException (util.js:746:11)
at Agent.Server._listen2 (net.js:1146:14)
at listen (net.js:1172:10)
at Agent.Server.listen (net.js:1257:5)
at Object.start (_debugger_agent.js:20:9)
at startup (node.js:86:9)
at node.js:814:3
Should I switch to another port? Is the debugger using 9000?
Please sign in to leave a comment.
What Node.js version do you use? Looks similar to https://github.com/angular/protractor/issues/2039
problem may be caused by the way Grunt spawns child tasks. By default, the spawned child process uses the same debug port as a parent process.
Please try adding 'process.execArgv = [];' to the top of gruntfile.js - does it help?
Adding process.execArgv = []; to the top of the gruntfile allows the process to complete without a debugging conflict, but will not stop at any breakpoints or allow any actual debugging. It essentially acts like a run task at that point.
I also tried removing the old node --debug-brk and adding one for the grunt task using a solution I saw suggested, but this did not work. It removes the debug-brk, adds a new one, then immediately bombs out without running a test.
Adding this to the Gruntfile.js results in an obscure failure:
Please try using Node.js Run configuration instead of Grunt configuration for debugging:
Working directory: <project root dir>
JavaScript file: /path/to/grunt-cli/bin/grunt
Application parameters: protractor etc.
It's not possible to debug child processes using Grunt run configuration, see https://youtrack.jetbrains.com/issue/WEB-16786
Similar results.
Did you add process.execArgv = [] to your gruntfile? problem spawning child processes
is not specific to run configuration being used, you still need to make sure that child
process is using a different debug port
Similarly adding process.execArgv = []; to the top of the gruntfile allows the process to complete without a debugging conflict, but will not stop at any breakpoints or allow any actual debugging. It essentially acts like a run task at that point.
Actually this allows me to debug the grunt task, but not the child process. I misspoke. I could also do that with a grunt debug configuration as well and didn't realize it because that wasn't what I was trying to debug.
Seems the problem is that the child process (protractor) is spawned without '--debug' option, and thus debugger can't attach to it: by default,
grunt.util.spawn() inherits process arguments and starts child process with same options as the main process, causing EADDRINUSE; adding 'process.execArgv = []' helps to proceed with process execution, but now process.execArgv is empty, and child process is started without debug option. So, you have to modify the task runner accordingly.... For example, if you are using 'grunt-protractor-runner', you have to modify grunt-protractor-runner\tasks\protractor_runner.js. For example, by adding