When running the JavaScript tests on our current codebase, it takes too long to initialize and run tests. This is big slowdown, especially for someone who doesn’t have much experience with Jasmine or Angular.

Ideally for me would be if I could:

  • run specific tests
  • being able to breakpoint and debug test in Chrome Dev tools
  • auto update, so I could just add line of code to test and refresh the page

The following changes might be specicific for our codebase setup.

How To Do It

  1. When running tests, use fdiscribe and fit which will focus on specific spec or sepcific test. (Jasmin focused_spec.js)

  2. Install karma-cli (StackOverflow #1)

    npm install karma-cli -g

  3. In static/karma.conf.js set autoWatch to be True, so the new changes in files will be automatically picked up. (Newtriks LTD blog)

    autoWatch: true

  4. Run tests using karma-cli (StackOverflow #2)

    $> cd project_folder

    $> cd static

    $> karma start karma.conf.js --browser=Chrome --single-run=false --reports=html

  5. After the karma test starts, the new Chrome window will open up. Click on Debug in new window.

    Chrome window when starting test

  6. In new tab, open developers tools and you have access to all running tests.

    Chrome debugging using Dev Tools

When you edit your tests or specs, just refresh the tab with developer console open and the changes should be immediately visible.