karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.94k stars 1.71k forks source link

Extending Karma reporter from Typescript #3236

Open Raagh opened 5 years ago

Raagh commented 5 years ago

Hey guys, so i need to create new reporter for karma, specifically for building a vscode extension for running angular tests. How can I extend the Karma Reporter from typescript? all the examples I found are custom reporters created from javascript and set in the configuration file.

is there a way to add a reporter programatically? are there any typings made of the complete karma runner solution?

johnjbarton commented 5 years ago

A TypeScript reporter can be added exactly the way a JS reporter is added. Your reporter exports the dependency injection string:

export = {
  'reporter:XXXX': ['type', implXXXX]
};

and your config adds the reporter:

module.exports = function(config) {
  config.reporters = (config.reporters || []).concat(['XXXX']);
};

The API is confusing and not documented but also simple enough, just look at reporter examples to work it out. Note that in general the reporter is a client of the test framework, not really of karma-runner. The runner API is essentially a few events like onBrowseInfo onBrowserComplete with data forwarded from the framework.

are there any typings made of the complete karma runner solution?

None covering reporters that I know about.