Skip to content

Commit

Permalink
chore: add test and docs for high and low watermarks (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Jan 17, 2017
1 parent 0a1d72a commit 7708235
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Expand Up @@ -312,6 +312,31 @@ nyc
└── /usr/local/bin/node /path/to/your/project/node_modules/ava/lib/test-worker.js …
```

## High and low watermarks

Several of the coverage reporters supported by nyc display special information
for high and low watermarks:

* high-watermarks represent healthy test coverage (in many reports
this is represented with green highlighting).
* low-watermarks represent sub-optimal coverage levels (in many reports
this is represented with red highlighting).

You can specify custom high and low watermarks in nyc's configuration:

```json
{
"nyc": {
"watermarks": {
"lines": [80, 95],
"functions": [80, 95],
"branches": [80, 95],
"statements": [80, 95]
}
}
}
```

## Integrating with coveralls

[coveralls.io](https://coveralls.io) is a great tool for adding
Expand Down
35 changes: 35 additions & 0 deletions test/src/nyc-bin.js
Expand Up @@ -689,4 +689,39 @@ describe('the nyc cli', function () {
done()
})
})

it('allows alternative high and low watermarks to be configured', function (done) {
var args = [
bin,
'--watermarks.lines=90',
'--watermarks.lines=100',
'--watermarks.statements=30',
'--watermarks.statements=40',
'--cache=true',
process.execPath,
'./half-covered.js'
]

var proc = spawn(process.execPath, args, {
cwd: fixturesCLI,
env: {
PATH: process.env.PATH,
FORCE_COLOR: true
}
})

var stdout = ''
proc.stdout.on('data', function (chunk) {
stdout += chunk
})

proc.on('close', function (code) {
code.should.equal(0)
// 50% line coverage is below our low watermark (so it's red).
stdout.should.match(/\[91m\W+50\W+/)
// 50% statement coverage is above our high-watermark (so it's green).
stdout.should.match(/\[92m\W+50\W+/)
done()
})
})
})

0 comments on commit 7708235

Please sign in to comment.