If you use the karma-phantomjs-launcher npm package in your karma tests, you can add the following snippet in the karma.conf.js file to run PhantomJS in debug mode:
browsers: ['PhantomJS_custom'], // you can define custom flags customLaunchers: { 'PhantomJS_custom': { base: 'PhantomJS', debug: true } }
Then write the debugger; statement debugger; where you want to put the breakpoint in your code.
Now, when you start the karma test drive, you will see that PhantomJS is waiting for your browser to connect to the debugger port to start the tests.
29 12 2016 13:14:25.269:INFO [launcher]: Starting browser PhantomJS 29 12 2016 13:14:25.325:INFO [phantomjs.launcher]: ACTION REQUIRED: 29 12 2016 13:14:25.325:INFO [phantomjs.launcher]: 29 12 2016 13:14:25.326:INFO [phantomjs.launcher]: Launch browser at 29 12 2016 13:14:25.326:INFO [phantomjs.launcher]: http://localhost:9000/webkit/inspector/inspector.html?page=2 29 12 2016 13:14:25.326:INFO [phantomjs.launcher]: 29 12 2016 13:14:25.326:INFO [phantomjs.launcher]: Waiting 15 seconds ...
Point your chrome to the address indicated in the magazines. You will now see the debugger interface maintained by Phantomjs. The code runs in the PhantomJS engine, but you can observe breakpoints, evaluate expressions, and perform many debugging operations from any web-based browser.
source share