6

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.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

2 Answers2

6

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.

Preview
  • 35,317
  • 10
  • 92
  • 112
  • This is really nice of you to implement the feature! I've tried that - this is exactly what I was asking about. I think this might be a useful feature to have in `karma-browserstack-launcher`. Many thanks! – alecxe Sep 23 '14 at 21:08
  • You're welcome :) Hum then I should see if I can open a PR on the repo, but I'm scared to be denied, mostly because of my formatting that might not please to everyone. But I'll keep you in touch ! – Preview Sep 23 '14 at 21:16
  • Thank you very much again for the effort you made. I think it would be a good idea to start an issue on karma-browserstack-launcher's github page and see what maintainers think about the feature. I think I'm not the only one who is missing this sort of functionality. Do you want me to create the issue, or you were going to send them a PR with changes? Thanks. – alecxe Sep 27 '14 at 03:33
  • I think I'm gonna review what I can improve and submit a PR which asks about the formatting, the parameter name and the use of chalk or not. Probably today or tomorrow. Glad to have helped ! :) – Preview Sep 27 '14 at 05:56
  • 2
    @alecxe [here](https://github.com/karma-runner/karma-browserstack-launcher/pull/14) is the PR for reference – Preview Oct 15 '14 at 19:49
  • 1
    Thank you for letting me know. Would be glad to see it merged. – alecxe Oct 15 '14 at 20:26
3

Not really karma-specific, but you could use https://github.com/sindresorhus/time-grunt to see how long the entire unit:remote task takes.

Just copying from its readme.md, you can install it using

npm install --save-dev time-grunt

And then edit your gruntfile as

// Gruntfile.js
module.exports = function (grunt) {
  // require it at the top and pass in the grunt instance
  require('time-grunt')(grunt);

  grunt.initConfig();
}

Then when you run grunt tasks(s) you should get output like:

time-grunt example

Michal Charemza
  • 25,940
  • 14
  • 98
  • 165
  • Strictly speaking, this is a workaround, but is really good to know about. Thank you very much for bringing this up. – alecxe Sep 22 '14 at 00:45