Thursday, January 11, 2018

Karma - custom adapter with dynamically updated number of total tests

Leave a Comment

I'm creating a custom adapter for Karma. While in other adapters I looked on (e.g. karma-mocha) the total number of tests is reported on the beginning of the execution (via info call), for my case it cannot be done on the beginning as total tests number is not known then.

I tried invoking info method after every test suite (sending number of tests executed) is executed but it seems it does not take any effect (looks like it is only updated on the beginning of the whole test run). Is it possible to achieve with some other approach or maybe custom reporter?

P.S. I know updating total number of tests after executing every test suite doesn't have much value as the user will still not see total number of tests before running them. However, "Executed 550 of 550" still looks better than "Executed 550 of 0".

1 Answers

Answers 1

Looks like Karma does something special when info is called before test results are reported.

this.info = function (info) {     // TODO(vojta): introduce special API for this     if (!startEmitted && util.isDefined(info.total)) {         socket.emit('start', info)         startEmitted = true     } else {         socket.emit('info', info)     } } 

You could try keeping track of your test results/errors, then after the test run has finished call info with the total number of tests before calling result, error, and complete respectively.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment