Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

docs(readme): Document automatic setup #15

Merged
merged 4 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 168 additions & 137 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,137 +1,168 @@
[![Build Status](https://travis-ci.org/stryker-mutator/stryker-karma-runner.svg?branch=master)](https://travis-ci.org/stryker-mutator/stryker-karma-runner)
[![NPM](https://img.shields.io/npm/dm/stryker-karma-runner.svg)](https://www.npmjs.com/package/stryker-karma-runner)
[![Node version](https://img.shields.io/node/v/stryker-karma-runner.svg)](https://img.shields.io/node/v/stryker-karma-runner.svg)
[![Gitter](https://badges.gitter.im/stryker-mutator/stryker.svg)](https://gitter.im/stryker-mutator/stryker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

#Stryker Karma Runner

A plugin to use the karma test runner in [Stryker](https://stryker-mutator.github.io), the JavaScript mutation testing framework

## Warning

The stryker-karma-runner is available from stryker v0.4.0 onward.

## Install

Install stryker-karma-runner from your project folder:

```bash
npm i --save-dev stryker-karma-runner
```

## Peer dependencies

The `stryker-karma-runner` is a pluggin for `stryker` to enable `karma` as a test runner. As such you should install the correct versions of the dependencies:

* `karma`: version ^0.13.0 || ^1.0.0
* `karma-coverage`: version ^0.5.5 || ^1.0.0
* `stryker-api`: version ^0.0.2

These are marked as `peerDependencies` of `stryker-karma-runner` so you should get a warning when the correct versions are not installed.
*Note*: Karma itself also requires some plugins to work.

## Configuring

You can either configure the karma test runner from the `stryker.conf.js` file or from the command line. This readme describes how to do it via the config file.

### Load the plugin

In order to use the `stryker-karma-runner` it must me loaded in the stryker mutation testing framework via the stryker configuration.
Easiest is to *leave out* the `plugins` section from your config entirely. That way, all node_modules starting with `stryker-` will be loaded.

If you do decide to choose specific modules, don't forget to add `'stryker-karma-runner'` to the list of plugins to load.

### Use the test runner

Specify the use of the karma testRunner: `testRunner: 'karma'`.

### Karma config

When the Stryker uses the karma test runner, it uses these default karma config settings:

```javascript
{
browsers: ['PhantomJS'], // *
frameworks: ['jasmine'], // *
autoWatch: false,
singleRun: false,
}
// * these settings can be overriden, see next paragraph
```

For the first test run, stryker enables code coverage. If so, these additional settings are used:

```javascript
coverageReporter: {
type: 'in-memory'
},
preprocessors: {
'src/file1.js': 'coverage', // for each file to be mutated
'src/file2.js': 'coverage'
},
plugins: ['karma-coverage'] // or left blank (by default, karma loads all plugins starting with karma-*
```

#### Override karma config

You can override karma config by adding a `karmaConfig` property to your `stryker.conf.js` file.

For example:

```javascript
karmaConfig: {
browsers: ['Chrome'],
frameworks: ['mocha']
}
```

*Note*: Whichever testFramework you use should also be reflected in the `testFramework` property of stryker itself. For example: `testFramework: 'mocha'`

Not all karma config can be overriden, as Stryker requires specific functionality from the testRunner to do its magic.
Karma config that *cannot* be overriden:

* `files`: The karma-runner will fill this based on the `files` and `filesToMutate` configuration in the `stryker-conf.js` file.
* `coverageReporter`: This will be enabled for the initial test run, disabled for testing the mutants.
* `autoWatch`, `singleRun`: Stryker needs full control on when to run the karma tests

### Full config example

```javascript
// stryker.conf.js
exports = function(config){
config.set({
// ...
testRunner: 'karma',
testFramework: 'jasmine',
karmaConfig: { // these are the defaults
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
autoWatch: false,
singleRun: false
},
plugins: ['stryker-karma-runner'] // Or leave out the plugin list entirely to load all stryker-* plugins directly
// ...
});
}
```

## Usage

Use Stryker as you normally would.
See [http://stryker-mutator.github.io](http://stryker-mutator.github.io) for more info.

### Debugging

By default, karma logging will be swallowed.
Set log level to `trace` in `stryker.conf.js` to see all the karma output.

```javascript
// stryker.conf.js
exports = function(config){
config.set({
// ...
logLevel: 'trace'
// ...
});
}
```
[![Build Status](https://travis-ci.org/stryker-mutator/stryker-karma-runner.svg?branch=master)](https://travis-ci.org/stryker-mutator/stryker-karma-runner)
[![NPM](https://img.shields.io/npm/dm/stryker-karma-runner.svg)](https://www.npmjs.com/package/stryker-karma-runner)
[![Node version](https://img.shields.io/node/v/stryker-karma-runner.svg)](https://img.shields.io/node/v/stryker-karma-runner.svg)
[![Gitter](https://badges.gitter.im/stryker-mutator/stryker.svg)](https://gitter.im/stryker-mutator/stryker?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

#Stryker Karma Runner

A plugin to use the karma test runner in [Stryker](https://stryker-mutator.github.io), the JavaScript mutation testing framework

## Install

Install stryker-karma-runner locally within your project folder, like so:

```bash
npm i --save-dev stryker-karma-runner
```

## Peer dependencies

The `stryker-karma-runner` is a plugin for `stryker` to enable `karma` as a test runner.
As such, you should make sure you have the correct versions of its dependencies installed:

* `karma`
* `stryker-api`

For the current versions, see the `peerDependencies` section in the [package.json](https://github.com/stryker-mutator/stryker-karma-runner/blob/master/package.json).

These are marked as `peerDependencies` of `stryker-karma-runner` so you get a warning during installation when the correct versions are not installed.
*Note*: Karma itself also requires some plugins to work.

## Configuring

You can either configure the karma test runner using the command line or by providing it in the `stryker.conf.js` file.
This README describes how to use the `stryker.conf.js` config file.

### Load the plugin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the plugin


In order to use the `stryker-karma-runner` it must me loaded in the stryker mutation testing framework via the stryker configuration.
The easiest way to achieve this, is *not have a `plugins` section* in your config file. That way, all `node_modules` starting with `stryker-` will be loaded.

If you do decide to choose specific modules, don't forget to add `'stryker-karma-runner'` to the list of plugins to load.

### Use the test runner

In order to use karma as the test runner, you simply specify it in your config file: `testRunner: 'karma'`

### Karma config

#### Automatic setup

You can configure stryker to use *your very own* `karma.conf.js` file.

```javascript
// Stryker.conf.js
module.exports = function (config) {
config.set({
testRunner: 'karma',
testFramework: 'jasmine', // <-- add your testFramework here
karmaConfigFile: 'karma.conf.js' // <-- add your karma.conf.js file here
mutate: [
'src/**/*.js' // <-- mark files for mutation here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select the files to mutate here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, its not selecting. File selection is done via the files property.

]
});
}
```

This will configure three things for you:

* Karma's `files` option will be used to configure the files in Stryker, you don't need to keep a list of files in sync in both `stryker.conf.js` and `karma.conf.js`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Karma's files option will be used to configure the files in Stryker. This relives you from the burden to keep the list of files in sync in stryker.conf.js and karma.conf.js.

* Karma's `exclude` option will be used to ignore files in Stryker (using `!` to ignore them)
* All remaining karma config options will be copied to the `karmaConfig` option in Stryker config. They will be picked up by the `stryker-karma-runner` during mutation testing.
* **Note**: Any manual setup you configure in the `karmaConfig` options will *not* be overwritten.

#### Manual setup

**Note**: Using the manual setup will not read your `karma.conf.js` options. You'll probably need to *Override the karma config* (see next section)

When Stryker uses the karma test runner, it uses these default karma config settings:


```javascript
{
browsers: ['PhantomJS'], // *
frameworks: ['jasmine'], // *
autoWatch: false,
singleRun: false,
}
// * these settings can be overriden, see next paragraph
```

For the first test run, stryker enables code coverage. If so, these additional settings are used:

```javascript
coverageReporter: {
type: 'in-memory'
},
preprocessors: {
'src/file1.js': 'coverage', // for each file to be mutated
'src/file2.js': 'coverage'
},
plugins: ['karma-coverage'] // or left blank (by default, karma loads all plugins starting with karma-*
```

#### Override karma config

You can override karma config by adding a `karmaConfig` property to your `stryker.conf.js` file.

For example:

```javascript
karmaConfig: {
browsers: ['Chrome'],
frameworks: ['mocha']
}
```

*Note*: Whichever testFramework you use should also be reflected in the `testFramework` property of stryker itself. For example: `testFramework: 'mocha'`

Not all karma config can be overriden, as Stryker requires specific functionality from the testRunner to do its magic.

The following Karma config options cannot be overridden:

* `files`: The karma-runner will fill this based on the `files` and `mutate` configuration in the `stryker-conf.js` file (or your `karma.conf.js` file when using the *automatic setup*).
* `coverageReporter`: For the initial test run, the `stryker-karma-runner` will use its own coverage reporter. For testing the mutants, however, it will be disabled.
* `autoWatch`, `singleRun`: Stryker needs full control on when to run the karma tests

### Full config example

```javascript
// stryker.conf.js
exports = function(config){
config.set({
// ...
testRunner: 'karma',
testFramework: 'jasmine',
karmaConfig: { // these are the defaults
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
autoWatch: false,
singleRun: false
},
plugins: ['stryker-karma-runner'] // Or leave out the plugin list entirely to load all stryker-* plugins directly
// ...
});
}
```

## Usage

Use Stryker as you normally would.
See [http://stryker-mutator.github.io](http://stryker-mutator.github.io) for more info.

### Debugging

As Stryker runs karma in its own process, its logging output will be consumed by Stryker.

To see all logging from karma, set the log level to `trace` in `stryker.conf.js`.

```javascript
// stryker.conf.js
exports = function(config){
config.set({
// ...
logLevel: 'trace'
// ...
});
}
```
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.js",
"scripts": {
"test": "grunt test",
"preversion": "npm run test"
"preversion": "npm run test",
"start": "tsc -w"
},
"repository": {
"type": "git",
Expand Down