Debugging Jasmine Unit tests in Intellij IDEA

Writing unit tests is a thing we do at Aftonbladet, and our front end JavaScript is no exception. We are currently using GruntJS to (amongst other things) run our Jasmine specs / unit tests in PhantomJS as part of our development workflow.


We also tend to use the Intellij IDEA IDE from JetBrains.

I have been having a not-so-great time refactoring a piece of JS code recently, breaking existing unit tests in ways I didn’t expect. When working on backend code (Java, or whatever) I’d just run the failing test in my IDE using the debugger to inspect the running code. The process for debugging javascript/jasmine unit tests have been less straightforward, in part due to our somewhat complicated GruntJS setup. Ideally, I wanted to simply run the debugger from inside my IDE at the click of a button, rather than having to go through a set of manual steps and switching from my IDE context. Here’s what I did:

1. Make sure NodeJS and Grunt were properly installed and configured
2. Install the NodeJS plugin for IDEA
3. Get the JetBrains IDE support browser extension from the chrome web store.
4. Set up a grunt-jasmine  task (I also set up a jasmine task, “mytarget”, but that is optional) to generate a _SpecRunner.html template. Adding the :build flag/option to the grunt-jasmine task will have it generate a SpecRunner file rather than running the tests.
5. Create a new Node Run/Debug configuration in IntelliJ, indicating the project directory as Working directory, the path to the GruntJS install as JavaScript file and the test-task (“jasmine:mytarget:build” in my case) in the Application parameters field. It is also possible to add the  –filter -flag as an application parameter, to generate a SpecRunner that only runs a subset of the specs.
debugging-intellij-1

6. Enable the option to launch the Chrome browser with the IDE debugger when the grunt task is done, opening the _SpecRunner.html file.
.debugging-intellij-2
7. Set breakpoints in javascript or spec files, and run/debug the new configuration config.

I realize it should be possible to connect the IntelliJ debugger to the Node/Grunt process instead of running the tests in a Chrome browser, but as it turned out to be surprisingly tricky for me to get the breakpoints to take effect this Chrome-based solution solved my problem with a lot less fiddling around.


A Holistic View on Developer Productivity

What does developer productivity mean, really? Is it churning out more code or less code? Is it to have less bugs in production or shipping code more often? Is it doing a lot of things or just one thing? Let’s think about this for a moment. I believe developer productivity is about getting more things […]


Improving the usability of Aftonbladet Video-clip pages

We have recently started the process of improving the usability of video-clip pages. In order to get an idea of where Aftonbladet stands compared to other world-class online video/news providers, we conducted an online test answered by 110 visitors of Aftonbladet TV. In this test we compared their perception of an Aftonbladet TV video-clip page […]


Schibsted’s 1st iOS Deployment Meet-up

Schibsted’s 1st iOS Deployment Meet-up Thursday, 28th of April 2016: getting to know each other, guests arrive Friday, 29th of April 2016: the meet-up date We here at Aftonbladet had been planning on having a meet-up with iOS developers across various Schibsted companies for many months. We had a range of topics in mind for […]


Hackday: The Future of Storytelling is social, engaging and rewarding

We gathered students, journalists, developers and designers to get together and conceptualize something new for the news industry. This was our first organized hack event – The Future of Storytelling Hack. The hack was a team-based, news-media-focused prototyping and experimentation event within storytelling over two days at Kungsbrohuset, Schibsted and Aftonbladets headquarter in Stockholm. A good story used to […]