L1ghtk3ira
L1ghtk3ira

Reputation: 3199

Grunt+Karma: Show code coverage report in browser every time tests are ran

I started using a Karma test coverage report for testing my Angular applications. The file and folder generate fine however I have to go into the folder and run the index page manually to see the results.

I would like it so that when I run my tests the Karma coverage report html file will open up automatically in the browser for me to view. Every time after that when tests run the code coverage html file should refresh with the new results.

I have looked online and cannot seem to find how to do this. It seems trivial to have to manually open up the test coverage report. There should be some sort of way using Karma or Grunt to do this for me.

Upvotes: 1

Views: 772

Answers (1)

Jordan Kasper
Jordan Kasper

Reputation: 13273

You can use the connect task to do this as the last step in your grunt process. It will start a simple static server, serving whatever directory you want, and can open your default browser for URLs. Check the docs for options, but here's a simple stab at it:

connect: {
  server: {
    options: {
      port: 8000,
      hostname: 'localhost',
      base: 'coverage/', // or whatever directory your reports are in
      open: true
    }
  }
}

Don't forget to add the connect task to the end of your alias (like "default" or whatever)

Upvotes: 0

Related Questions