Howto debug a karma testrun


Hello! How can I debug my karma testrunner? What is the nodejs command line for running karma programatically?

I can run my tests from the bash with `karma start test/unit/karma.conf.js --single-run``

But how do I run that as a node.js run configuration, so that I can debug my testcases?


If your test uses phantomjs to run, you can’t debug it with cloud9, you can open teest in browser and use developer tools to debug it.


Hello cloud9 Support! Thank you for the quick reply. I completely agree with you that I cannot debug End-2-end tests that run in another browser (which is steered via selenium API). But I thought that a headless browser like phantomjs is nothing else than any other javascript “script” that could theoretically be debugged inside cloud9.

But ok, meanwhile I found my bug with the method you suggested: A lot of ‘hand made’ debugging in the browser console with lot of console.log commands.


Actually, it can run on a ‘real’ browser (e.g. Chromium) in ‘headless’ mode as well - one just needs to install xvfb-run and prepend it to any test command (or better still, xvfb-run -a to assign a virtual display port automatically).

This approach works for Karma tests. But you may just as well open the test in another tab on your device’s browser if you prefer to see it ‘in action’. You may not notice any useful content though, as the tests usually run very quickly; you would also need to keep that tab open for the duration of your tests. For debugging though (if you want to set breakpoints) I think this is the best way to go (you can print-debug ‘virtual’ sessions, but that can be painful).

It also works for e2e tests - one just needs to take ‘screenshots’. E.g. I can run Protractor tests and use browser.takeScreenshot() to capture the current state.

EDIT: corrected my earlier suggestion that Protractor can run without Xvfb - which in fact it can’t, at least yet.