Skip to content

Commit

Permalink
docs: Cleanup documentation and add running coffee example
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Jun 11, 2015
1 parent d68d4ba commit e19feaa
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 250 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
examples/coffee/coverage
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.*
test

examples/coffee/coverage
Gruntfile.coffee
CONTRIBUTING.md
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ node_js:

# Make sure we have new NPM.
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- npm install -g npm
- npm config set loglevel warn

Expand Down
256 changes: 9 additions & 247 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ npm install karma karma-coverage --save-dev

## Configuration

The following code shows a simple usage:
For configuration details see [docs/configuration](docs/configuration.md).

## Examples

### Basic

```javascript
// karma.conf.js
Expand Down Expand Up @@ -47,45 +51,12 @@ module.exports = function(config) {
});
};
```
### CoffeeScript

Example use with a CoffeeScript project:

```javascript
// karma.conf.js
module.exports = function(config) {
config.set({
files: [
'src/**/*.coffee',
'test/**/*.coffee'
],
For an example on how to use with [CoffeeScript](http://coffeescript.org/)
see [examples/coffee](examples/coffee).

// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],

preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul via Ibrik unless
// specified otherwise in coverageReporter.instrumenter)
'src/**/*.coffee': ['coverage'],

// note: project files will already be converted to
// JavaScript via coverage preprocessor.
// Thus, you'll have to limit the CoffeeScript preprocessor
// to uncovered files.
'test/**/*.coffee': ['coffee']
},

// optionally, configure the reporter
coverageReporter: {
type : 'html',
dir : 'coverage/'
}
});
};
```

Here is an advanced usage of karma-coverage, using severals reporters:
### Advanced, multiple reporters

```javascript
// karma.conf.js
Expand Down Expand Up @@ -119,215 +90,6 @@ module.exports = function(config) {
});
```

### Options
#### type
**Type:** String

**Description:** Specify a reporter type.

**Possible Values:**
* `html` (default)
* `lcov` (lcov and html)
* `lcovonly`
* `text`
* `text-summary`
* `cobertura` (xml format supported by Jenkins)
* `teamcity` (code coverage System Messages for TeamCity)
* `json` (json format supported by [`grunt-istanbul-coverage`](https://github.com/daniellmb/grunt-istanbul-coverage))

#### dir
**Type:** String

**Description:** This will be used to output coverage reports. When
you set a relative path, the directory is resolved against the `basePath`.

#### subdir
**Type:** String

**Description**: This will be used in complement of the `coverageReporter.dir`
option to generate the full output directory path. By default, the output
directory is set to `./config.dir/BROWSER_NAME/`, this option allows you to
custom the second part. You can either pass a `string` or a `function` which will be
called with the browser name passed as the only argument.

```javascript
coverageReporter: {
dir: 'coverage',
subdir: '.'
// Would output the results into: .'/coverage/'
}
```

```javascript
coverageReporter: {
dir: 'coverage',
subdir: 'report'
// Would output the results into: .'/coverage/report/'
}
```

```javascript
coverageReporter: {
dir: 'coverage',
subdir: function(browser) {
// normalization process to keep a consistent browser name accross different
// OS
return browser.toLowerCase().split(/[ /-]/)[0];
}
// Would output the results into: './coverage/firefox/'
}
```

#### file

If you choose the `cobertura`, `lcovonly`, `teamcity`, `text` or `text-summary` reporters, you may set the `file` option to specify an output file.

```javascript
coverageReporter: {
type : 'text',
dir : 'coverage/',
file : 'coverage.txt'
}
```

#### check
**Type:** Object

**Description:** This will be used to configure minimum threshold enforcement for coverage results. If the thresholds are not met, karma will return failure. Thresholds, when specified as a positive number are taken to be the minimum percentage required. When a threshold is specified as a negative number it represents the maximum number of uncovered entities allowed.

For example, `statements: 90` implies minimum statement coverage is 90%. `statements: -10` implies that no more than 10 uncovered statements are allowed.

`global` applies to all files together and `each` on a per-file basis. A list of files or patterns can be excluded from enforcement via the `exclude` property. On a per-file or pattern basis, per-file thresholds can be overridden via the `overrides` property.

```javascript
coverageReporter: {
check: {
global: {
statements: 50,
branches: 50,
functions: 50,
lines: 50,
excludes: [
'foo/bar/**/*.js'
]
},
each: {
statements: 50,
branches: 50,
functions: 50,
lines: 50,
excludes: [
'other/directory/**/*.js'
],
overrides: {
'baz/component/**/*.js': {
statements: 98
}
}
}
}
}
```

#### watermarks
**Type:** Object

**Description:** This will be used to set the coverage threshold colors. The first number is the threshold between Red and Yellow. The second number is the threshold between Yellow and Green.

```javascript
coverageReporter: {
watermarks: {
statements: [ 50, 75 ],
functions: [ 50, 75 ],
branches: [ 50, 75 ],
lines: [ 50, 75 ]
}
}
```

#### includeAllSources
**Type:** Boolean

You can opt to include all sources files, as indicated by the coverage preprocessor, in your code coverage data, even if there are no tests covering them. (Default `false`)

```javascript
coverageReporter: {
type : 'text',
dir : 'coverage/',
file : 'coverage.txt',
includeAllSources: true
}
```

#### sourceStore
**Type:** istanbul.Store

You can opt to specify a source store allowing for external coverage collectors access to the instrumented code.

```javascript
coverageReporter: {
type : 'text',
dir : 'coverage/',
file : 'coverage.txt',
sourceStore : require('istanbul').Store.create('fslookup')
}
```

#### multiple reporters
You can use multiple reporters, by providing array of options.

```javascript
coverageReporter: {
reporters:[
{type: 'html', dir:'coverage/'},
{type: 'teamcity'},
{type: 'text-summary'}
],
}
```

#### instrumenter
Karma-coverage can infers the instrumenter regarding of the file extension.
It is possible to override this behavior and point out an
instrumenter for the files matching a specific pattern.
To do so, you need to declare an object under with the keys represents the
pattern to match, and the instrumenter to apply. The matching will be done
using [minimatch](https://github.com/isaacs/minimatch).
If two patterns match, the last one will take the precedence.

For example you can use [Ibrik](https://github.com/Constellation/ibrik) (an
[Istanbul](https://github.com/gotwarlost/istanbul) analog for
CoffeeScript files) with:

```javascript
coverageReporter: {
instrumenters: { ibrik : require('ibrik') }
instrumenter: {
'**/*.coffee': 'ibrik'
},
// ...
}
```

You can pass options additional options to specific instrumenter with:

```javascript
var to5Options = { experimental: true };

// [...]

coverageReporter: {
instrumenters: { isparta : require('isparta') },
instrumenter: {
'**/*.js': 'isparta'
},
instrumenterOptions: {
isparta: { to5 : to5Options }
}
}
```


----

For more information on Karma see the [homepage].
Expand Down
Loading

0 comments on commit e19feaa

Please sign in to comment.