nyc 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +16 -1
- package/bin/nyc.js +60 -25
- package/index.js +23 -24
- package/package.json +7 -7
- package/test/nyc-test.js +27 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
+
### v2.4.0 (2015/06/24 15:57 +00:00)
|
|
4
|
+
- [#30](https://github.com/bcoe/nyc/pull/30) Added check-coverage functionality, thanks
|
|
5
|
+
@Raynos! (@bcoe)
|
|
6
|
+
|
|
7
|
+
### v2.3.0 (2015/06/04 06:43 +00:00)
|
|
8
|
+
- [#27](https://github.com/bcoe/nyc/pull/27) upgraded tap, and switched tests to using tap --coverage (@bcoe)
|
|
9
|
+
- [#25](https://github.com/bcoe/nyc/pull/25) support added for multiple reporters, thanks @jasisk! (@jasisk)
|
|
10
|
+
|
|
3
11
|
### v2.2.0 (2015/05/25 21:05 +00:00)
|
|
4
12
|
- [b2e4707](https://github.com/bcoe/nyc/commit/b2e4707ca16750fe274f61039baf1cabdd6b0149) change location of nyc_output to .nyc_output. Added note about coveralls comments. (@sindresorhus)
|
|
5
13
|
|
package/README.md
CHANGED
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
[](https://coveralls.io/r/bcoe/nyc?branch=)
|
|
5
5
|
[](https://www.npmjs.com/package/nyc)
|
|
6
6
|
|
|
7
|
+
```shell
|
|
8
|
+
nyc npm test
|
|
9
|
+
```
|
|
10
|
+
|
|
7
11
|
a code coverage tool built on [istanbul](https://www.npmjs.com/package/istanbul)
|
|
8
|
-
that works
|
|
12
|
+
that works for applications that spawn subprocesses.
|
|
9
13
|
|
|
10
14
|
## Instrumenting Your Code
|
|
11
15
|
|
|
@@ -26,6 +30,17 @@ If you're so inclined, you can simply add nyc to the test stanza in your package
|
|
|
26
30
|
}
|
|
27
31
|
```
|
|
28
32
|
|
|
33
|
+
## Checking Coverage
|
|
34
|
+
|
|
35
|
+
nyc exposes istanbul's check-coverage tool. After running your tests with nyc,
|
|
36
|
+
simply run:
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
nyc check-coverage --lines 95 --functions 95 --branches 95
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This feature makes it easy to fail your tests if coverage drops below a given threshold.
|
|
43
|
+
|
|
29
44
|
## Running Reports
|
|
30
45
|
|
|
31
46
|
Once you've run your tests with nyc, simply run:
|
package/bin/nyc.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var foreground = require('foreground-child')
|
|
3
|
-
|
|
2
|
+
var foreground = require('foreground-child')
|
|
3
|
+
var path = require('path')
|
|
4
|
+
var sw = require('spawn-wrap')
|
|
4
5
|
|
|
5
6
|
if (process.env.NYC_CWD) {
|
|
6
7
|
var NYC = require('../')
|
|
@@ -13,36 +14,70 @@ if (process.env.NYC_CWD) {
|
|
|
13
14
|
|
|
14
15
|
sw.runMain()
|
|
15
16
|
} else {
|
|
16
|
-
var NYC = require('../')
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
17
|
+
var NYC = require('../')
|
|
18
|
+
var yargs = require('yargs')
|
|
19
|
+
.usage('$0 [command] [options]\n\nrun your tests with the nyc bin to instrument them with coverage')
|
|
20
|
+
.command('report', 'run coverage report for .nyc_output', function (yargs) {
|
|
21
|
+
yargs
|
|
22
|
+
.usage('$0 report [options]')
|
|
23
|
+
.option('r', {
|
|
24
|
+
alias: 'reporter',
|
|
25
|
+
describe: 'coverage reporter(s) to use',
|
|
26
|
+
default: 'text',
|
|
27
|
+
array: true
|
|
28
|
+
})
|
|
29
|
+
.help('h')
|
|
30
|
+
.alias('h', 'help')
|
|
31
|
+
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
|
|
32
|
+
})
|
|
33
|
+
.command('check-coverage', 'check whether coverage is within thresholds provided', function (yargs) {
|
|
34
|
+
yargs
|
|
35
|
+
.usage('$0 check-coverage [options]')
|
|
36
|
+
.option('b', {
|
|
37
|
+
alias: 'branches',
|
|
38
|
+
default: 0,
|
|
39
|
+
description: 'what % of branches must be covered?'
|
|
40
|
+
})
|
|
41
|
+
.option('f', {
|
|
42
|
+
alias: 'functions',
|
|
43
|
+
default: 0,
|
|
44
|
+
description: 'what % of functions must be covered?'
|
|
45
|
+
})
|
|
46
|
+
.option('l', {
|
|
47
|
+
alias: 'lines',
|
|
48
|
+
default: 90,
|
|
49
|
+
description: 'what % of lines must be covered?'
|
|
50
|
+
})
|
|
51
|
+
.help('h')
|
|
52
|
+
.alias('h', 'help')
|
|
53
|
+
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
|
|
54
|
+
})
|
|
55
|
+
.help('h')
|
|
56
|
+
.alias('h', 'help')
|
|
57
|
+
.version(require('../package.json').version)
|
|
58
|
+
.example('$0 npm test', 'instrument your tests with coverage')
|
|
59
|
+
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests')
|
|
60
|
+
.epilog('visit http://git.io/vTJJB for list of available reporters')
|
|
61
|
+
var argv = yargs.argv
|
|
38
62
|
|
|
39
|
-
if (
|
|
63
|
+
if (~argv._.indexOf('report')) {
|
|
40
64
|
// run a report.
|
|
41
65
|
process.env.NYC_CWD = process.cwd()
|
|
42
66
|
|
|
43
67
|
;(new NYC({
|
|
44
68
|
reporter: argv.reporter
|
|
45
69
|
})).report()
|
|
70
|
+
} else if (~argv._.indexOf('check-coverage')) {
|
|
71
|
+
foreground(
|
|
72
|
+
path.resolve(__dirname, '../node_modules/.bin/istanbul'),
|
|
73
|
+
[
|
|
74
|
+
'check-coverage',
|
|
75
|
+
'--lines=' + argv.lines,
|
|
76
|
+
'--functions=' + argv.functions,
|
|
77
|
+
'--branches=' + argv.branches,
|
|
78
|
+
path.resolve(process.cwd(), './.nyc_output/*.json')
|
|
79
|
+
]
|
|
80
|
+
)
|
|
46
81
|
} else if (argv._.length) {
|
|
47
82
|
// wrap subprocesses and execute argv[1]
|
|
48
83
|
;(new NYC()).cleanup()
|
package/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/* global __coverage__ */
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
stripBom = require('strip-bom')
|
|
2
|
+
var _ = require('lodash')
|
|
3
|
+
var fs = require('fs')
|
|
4
|
+
var mkdirp = require('mkdirp')
|
|
5
|
+
var path = require('path')
|
|
6
|
+
var rimraf = require('rimraf')
|
|
7
|
+
var onExit = require('signal-exit')
|
|
8
|
+
var stripBom = require('strip-bom')
|
|
10
9
|
|
|
11
10
|
function NYC (opts) {
|
|
12
11
|
_.extend(this, {
|
|
@@ -79,18 +78,18 @@ NYC.prototype._wrapRequire = function () {
|
|
|
79
78
|
}
|
|
80
79
|
|
|
81
80
|
NYC.prototype._wrapExit = function () {
|
|
82
|
-
var _this = this
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
var _this = this
|
|
82
|
+
var outputCoverage = function () {
|
|
83
|
+
var coverage = global.__coverage__
|
|
84
|
+
if (typeof __coverage__ === 'object') coverage = __coverage__
|
|
85
|
+
if (!coverage) return
|
|
86
|
+
|
|
87
|
+
fs.writeFileSync(
|
|
88
|
+
path.resolve(_this.tmpDirectory(), './', process.pid + '.json'),
|
|
89
|
+
JSON.stringify(coverage),
|
|
90
|
+
'utf-8'
|
|
91
|
+
)
|
|
92
|
+
}
|
|
94
93
|
|
|
95
94
|
// we always want to write coverage
|
|
96
95
|
// regardless of how the process exits.
|
|
@@ -106,8 +105,8 @@ NYC.prototype.wrap = function (bin) {
|
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
NYC.prototype.report = function (_collector, _reporter) {
|
|
109
|
-
var collector = _collector || new this.istanbul.Collector()
|
|
110
|
-
|
|
108
|
+
var collector = _collector || new this.istanbul.Collector()
|
|
109
|
+
var reporter = _reporter || new this.istanbul.Reporter()
|
|
111
110
|
|
|
112
111
|
this._loadReports().forEach(function (report) {
|
|
113
112
|
collector.add(report)
|
|
@@ -121,8 +120,8 @@ NYC.prototype.report = function (_collector, _reporter) {
|
|
|
121
120
|
}
|
|
122
121
|
|
|
123
122
|
NYC.prototype._loadReports = function () {
|
|
124
|
-
var _this = this
|
|
125
|
-
|
|
123
|
+
var _this = this
|
|
124
|
+
var files = fs.readdirSync(this.tmpDirectory())
|
|
126
125
|
|
|
127
126
|
return _.map(files, function (f) {
|
|
128
127
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nyc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "a code coverage tool that works well with subprocesses.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
"license": "ISC",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"foreground-child": "^1.2.0",
|
|
39
|
-
"istanbul": "^0.3.
|
|
39
|
+
"istanbul": "^0.3.16",
|
|
40
40
|
"lodash": "^3.8.0",
|
|
41
41
|
"mkdirp": "^0.5.0",
|
|
42
|
-
"rimraf": "^2.
|
|
42
|
+
"rimraf": "^2.4.0",
|
|
43
43
|
"signal-exit": "^2.1.1",
|
|
44
44
|
"spawn-wrap": "^1.0.1",
|
|
45
45
|
"strip-bom": "^1.0.0",
|
|
46
|
-
"yargs": "^3.
|
|
46
|
+
"yargs": "^3.12.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"chai": "^3.0.0",
|
|
50
|
-
"sinon": "^1.
|
|
51
|
-
"standard": "^4.
|
|
52
|
-
"tap": "^1.
|
|
50
|
+
"sinon": "^1.15.3",
|
|
51
|
+
"standard": "^4.3.2",
|
|
52
|
+
"tap": "^1.3.0"
|
|
53
53
|
},
|
|
54
54
|
"repository": {
|
|
55
55
|
"type": "git",
|
package/test/nyc-test.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* global describe, it */
|
|
2
2
|
|
|
3
|
-
var _ = require('lodash')
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
var _ = require('lodash')
|
|
4
|
+
var fs = require('fs')
|
|
5
|
+
var NYC = require('../')
|
|
6
|
+
var path = require('path')
|
|
7
|
+
var rimraf = require('rimraf')
|
|
8
|
+
var sinon = require('sinon')
|
|
9
|
+
var spawn = require('child_process').spawn
|
|
10
10
|
|
|
11
11
|
require('chai').should()
|
|
12
12
|
require('tap').mochaGlobals()
|
|
@@ -94,14 +94,14 @@ describe('nyc', function () {
|
|
|
94
94
|
describe('report', function () {
|
|
95
95
|
it('runs reports for all JSON in output directory', function (done) {
|
|
96
96
|
var nyc = new NYC({
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
cwd: process.cwd()
|
|
98
|
+
})
|
|
99
|
+
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
|
|
100
|
+
cwd: process.cwd(),
|
|
101
|
+
env: process.env,
|
|
102
|
+
stdio: 'inherit'
|
|
103
|
+
})
|
|
104
|
+
var start = fs.readdirSync(nyc.tmpDirectory()).length
|
|
105
105
|
|
|
106
106
|
proc.on('close', function () {
|
|
107
107
|
nyc.report(
|
|
@@ -130,13 +130,13 @@ describe('nyc', function () {
|
|
|
130
130
|
|
|
131
131
|
it('handles corrupt JSON files', function (done) {
|
|
132
132
|
var nyc = new NYC({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
cwd: process.cwd()
|
|
134
|
+
})
|
|
135
|
+
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
|
|
136
|
+
cwd: process.cwd(),
|
|
137
|
+
env: process.env,
|
|
138
|
+
stdio: 'inherit'
|
|
139
|
+
})
|
|
140
140
|
|
|
141
141
|
fs.writeFileSync('./.nyc_output/bad.json', '}', 'utf-8')
|
|
142
142
|
|
|
@@ -157,13 +157,13 @@ describe('nyc', function () {
|
|
|
157
157
|
})
|
|
158
158
|
|
|
159
159
|
it('handles multiple reporters', function (done) {
|
|
160
|
-
var reporters = ['text-summary', 'text-lcov']
|
|
161
|
-
incr = 0
|
|
162
|
-
nyc = new NYC({
|
|
160
|
+
var reporters = ['text-summary', 'text-lcov']
|
|
161
|
+
var incr = 0
|
|
162
|
+
var nyc = new NYC({
|
|
163
163
|
cwd: process.cwd(),
|
|
164
164
|
reporter: reporters
|
|
165
|
-
})
|
|
166
|
-
proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
|
|
165
|
+
})
|
|
166
|
+
var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
|
|
167
167
|
cwd: process.cwd(),
|
|
168
168
|
env: process.env,
|
|
169
169
|
stdio: 'inherit'
|