Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Total test execution time using karma runner

We've currently switched to running unit tests remotely on browserstack in multiple browsers on multiple operating systems with the help of karma-browserstack-launcher plugin.

Currently the output of the test run looks like this:

$ grunt unit:remote
Running "unit:remote" task

Running "karma:remote" (karma) task
INFO [karma]: Karma v0.12.23 server started at http://localhost:9876/
INFO [launcher]: Starting browser firefox 21.0 (OS X Mountain Lion) on BrowserStack
INFO [launcher]: Starting browser iPhone 5 (ios 6.0) on BrowserStack
INFO [launcher]: Starting browser android (android 4.1) on BrowserStack
INFO [launcher]: Starting browser ie 8.0 (Windows 7) on BrowserStack
INFO [launcher]: Starting browser ie 9.0 (Windows 7) on BrowserStack
INFO [launcher]: Starting browser chrome latest (OS X Mavericks) on BrowserStack
INFO [launcher]: Starting browser PhantomJS

PhantomJS 1.9.7 (Mac OS X): Executed 70 of 70 SUCCESS (0.063 secs / 0.275 secs)
Chrome 37.0.2062 (Mac OS X 10.9.0): Executed 70 of 70 SUCCESS (0 secs / 0.452 secs)
Mobile Safari 6.0.0 (iOS 6.1.4): Executed 70 of 70 SUCCESS (1.161 secs / 0.839 secs)
Firefox 21.0.0 (Mac OS X 10.8): Executed 70 of 70 SUCCESS (1.175 secs / 0.496 secs)
...

There is the execution time being reported for every browser.

Is there a way to see the total execution time on the console?


FYI, here is the karma config we are using.

like image 968
alecxe Avatar asked Sep 15 '14 20:09

alecxe


People also ask

How does Karma test Runner work?

Karma is essentially a tool which spawns a web server that executes source code against test code for each of the browsers connected. The results of each test against each browser are examined and displayed via the command line to the developer such that they can see which browsers and tests passed or failed.

Which of the following command is used to start the test runner in karma?

The ng test command builds the application in watch mode, and launches the Karma test runner.


1 Answers

I've forked the karma plugin and added an option extraLog in the karma browserStack config to get more information after all your browsers are finished, including the total execution and net time of all your browsers.

I'm mainly using the browser_complete event of the emitter that give me the total and the net time of the browser.

emitter.on('browser_complete', function (data) {
  result.browsers.push({ name: data.name, time: data.lastResult.totalTime });
  result.time.net += data.lastResult.netTime;
  result.time.total += data.lastResult.totalTime; //this is what we want
});

Using three browsers here an example output (sorry I'm not a designer yet) :

screen

This allows you to get a more accurate result in comparison with time-grunt.

You can review the code here on the feature-extra-logs branch.

I don't really know how do you want (and the best practice) to deploy this to you, because I don't think it is interesting enough to be merged to the upstream, but I might be wrong.

like image 198
Preview Avatar answered Nov 15 '22 08:11

Preview