nyc 2.1.4 → 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/.npmignore CHANGED
@@ -1,3 +1,3 @@
1
- nyc_output
1
+ .nyc_output
2
2
  coverage
3
3
  node_modules
package/.travis.yml CHANGED
@@ -1,9 +1,8 @@
1
1
  sudo: false
2
2
  language: node_js
3
3
  node_js:
4
- - '0.12'
5
- - '0.10'
6
- - iojs
4
+ - '0.12'
5
+ - '0.10'
6
+ - iojs
7
7
  env:
8
8
  - secure: "SVg7NpV0Sru296kdp+eFl07RFjtJy242fWQ1KDCUdk/1EtZEOzBoSKP7Tn3zX/VLBieexL0T31EwYvRztnL97Sr8VgpYU0z95vCPO8FrixElJR6NH3dqrKeNzC3xOYdV0fy2b4UMlPJOI0aYDT1KHm1aWtkb2J8zqII+XbMtlDaelfHCDxa2+RBII9nYYDP62z+0chQFS6MGPSNwve3G2emYHZpYP5iTFmOzaFUCAjLskKvnnsY0jyx5XssqAo17747WKZl5SDgN8YHZIwhE5tB9m9j3MGjJhwdsR3kmq2om0GD1tQFFAXzWhWad3zNBUE4fLqswgASi39o5NIEzvSRzpw77ttOkkIFGem0l421Zi25W8x5n6GZvP06Y47ddmjNBlniwIzG4fb3dbIByCy/g5SjUYmfnke7stXXBKsPv0eEadlLGFWnG5RIfnyGjvUgQ//QXSAnBBzYF9IK+KUdU8c9kHF6kPybsGEzjQoX+4EJL6kZ4sNX9qxjHERUr4Jb6rAMOnKI9VtCBNqwcCC3nV5DDWHS86hKwbuTbBFkszP7majOi0kUQJTO/tZGwVVcphSDwhL5QkmMepLOqXyRICdUcB2ffXHYhZLiZPofYdom8csaDolqFkotJEBj3GM3gwHvUC3i1vxshxtjF6NHjanhpiIpHLRCs6R1RESE="
9
- after_success: npm run coverage
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
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
+
11
+ ### v2.2.0 (2015/05/25 21:05 +00:00)
12
+ - [b2e4707](https://github.com/bcoe/nyc/commit/b2e4707ca16750fe274f61039baf1cabdd6b0149) change location of nyc_output to .nyc_output. Added note about coveralls comments. (@sindresorhus)
13
+
3
14
  ### v2.1.3 (2015/05/25 06:30 +00:00)
4
15
  - [376e328](https://github.com/bcoe/nyc/commit/376e32871d2d65ca31e7d8ba691293ac3ba6117e) handle corrupt JSON files in nyc_output (@bcoe)
5
16
 
package/README.md CHANGED
@@ -4,13 +4,17 @@
4
4
  [![Coverage Status](https://coveralls.io/repos/bcoe/nyc/badge.svg?branch=)](https://coveralls.io/r/bcoe/nyc?branch=)
5
5
  [![NPM version](https://img.shields.io/npm/v/nyc.svg)](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 well for applications that spawn subprocesses.
12
+ that works for applications that spawn subprocesses.
9
13
 
10
14
  ## Instrumenting Your Code
11
15
 
12
16
  Simply run your tests with `nyc`, and it will collect coverage information for
13
- each process and store it in `nyc_output`:
17
+ each process and store it in `.nyc_output`:
14
18
 
15
19
  ```shell
16
20
  nyc npm test
@@ -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:
@@ -118,3 +133,6 @@ after_success: npm run coverage
118
133
  ```
119
134
 
120
135
  That's all there is to it!
136
+
137
+ _Note: by default coveralls.io adds comments to pull-requests on GitHub, this can
138
+ feel intrusive. To disable this, click on your repo on coveralls.io and uncheck `LEAVE COMMENTS?`._
package/bin/nyc.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
- var foreground = require('foreground-child'),
3
- sw = require('spawn-wrap')
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,35 +14,70 @@ if (process.env.NYC_CWD) {
13
14
 
14
15
  sw.runMain()
15
16
  } else {
16
- var NYC = require('../'),
17
- yargs = require('yargs')
18
- .usage('$0 [command] [options]\n\nrun with a file as the first argument, to instrument it with coverage')
19
- .command('report', 'run coverage report on nyc_output', function (yargs) {
20
- yargs
21
- .option('r', {
22
- alias: 'reporter',
23
- describe: 'coverage reporter to use',
24
- default: 'text'
25
- })
26
- .help('h')
27
- .example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
28
- .alias('h', 'help')
29
- })
30
- .help('h')
31
- .alias('h', 'help')
32
- .version(require('../package.json').version)
33
- .example('$0 npm test', 'instrument your tests with coverage')
34
- .example('$0 report --reporter=text-lcov', 'output lcov report after running your tests')
35
- .epilog('visit http://git.io/vTJJB for list of available reporters'),
36
- argv = yargs.argv
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
37
62
 
38
- if (argv._.length && ~argv._.indexOf('report')) {
63
+ if (~argv._.indexOf('report')) {
39
64
  // run a report.
40
65
  process.env.NYC_CWD = process.cwd()
41
66
 
42
67
  ;(new NYC({
43
68
  reporter: argv.reporter
44
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
+ )
45
81
  } else if (argv._.length) {
46
82
  // wrap subprocesses and execute argv[1]
47
83
  ;(new NYC()).cleanup()
package/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  /* global __coverage__ */
2
-
3
- var _ = require('lodash'),
4
- fs = require('fs'),
5
- mkdirp = require('mkdirp'),
6
- path = require('path'),
7
- rimraf = require('rimraf'),
8
- onExit = require('signal-exit'),
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, {
@@ -14,9 +13,9 @@ function NYC (opts) {
14
13
  __dirname,
15
14
  './bin/nyc.js'
16
15
  ),
17
- tempDirectory: './nyc_output',
16
+ tempDirectory: './.nyc_output',
18
17
  cwd: process.env.NYC_CWD || process.cwd(),
19
- reporter: 'text',
18
+ reporter: ['text'],
20
19
  istanbul: require('istanbul')
21
20
  }, opts)
22
21
 
@@ -79,18 +78,18 @@ NYC.prototype._wrapRequire = function () {
79
78
  }
80
79
 
81
80
  NYC.prototype._wrapExit = function () {
82
- var _this = this,
83
- outputCoverage = function () {
84
- var coverage = global.__coverage__
85
- if (typeof __coverage__ === 'object') coverage = __coverage__
86
- if (!coverage) return
87
-
88
- fs.writeFileSync(
89
- path.resolve(_this.tmpDirectory(), './', process.pid + '.json'),
90
- JSON.stringify(coverage),
91
- 'utf-8'
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,21 +105,23 @@ 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
- reporter = _reporter || new this.istanbul.Reporter()
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)
114
113
  })
115
114
 
116
- reporter.add(this.reporter)
115
+ this.reporter.forEach(function (_reporter) {
116
+ reporter.add(_reporter)
117
+ })
117
118
 
118
119
  reporter.write(collector, true, function () {})
119
120
  }
120
121
 
121
122
  NYC.prototype._loadReports = function () {
122
- var _this = this,
123
- files = fs.readdirSync(this.tmpDirectory())
123
+ var _this = this
124
+ var files = fs.readdirSync(this.tmpDirectory())
124
125
 
125
126
  return _.map(files, function (f) {
126
127
  try {
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "nyc",
3
- "version": "2.1.4",
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": {
7
- "test": "standard && ./bin/nyc.js tap ./test/nyc-test.js",
8
- "coverage": "./bin/nyc.js report --reporter=text-lcov | coveralls"
7
+ "test": "standard && tap --coverage ./test/nyc-test.js"
9
8
  },
10
9
  "bin": {
11
10
  "nyc": "./bin/nyc.js"
@@ -37,22 +36,20 @@
37
36
  "license": "ISC",
38
37
  "dependencies": {
39
38
  "foreground-child": "^1.2.0",
40
- "istanbul": "^0.3.14",
41
- "jsonstream": "^1.0.3",
39
+ "istanbul": "^0.3.16",
42
40
  "lodash": "^3.8.0",
43
41
  "mkdirp": "^0.5.0",
44
- "rimraf": "^2.3.3",
42
+ "rimraf": "^2.4.0",
45
43
  "signal-exit": "^2.1.1",
46
44
  "spawn-wrap": "^1.0.1",
47
45
  "strip-bom": "^1.0.0",
48
- "yargs": "^3.8.0"
46
+ "yargs": "^3.12.0"
49
47
  },
50
48
  "devDependencies": {
51
- "chai": "^2.3.0",
52
- "coveralls": "^2.11.2",
53
- "sinon": "^1.14.1",
54
- "standard": "^3.7.3",
55
- "tap": "1.0.4"
49
+ "chai": "^3.0.0",
50
+ "sinon": "^1.15.3",
51
+ "standard": "^4.3.2",
52
+ "tap": "^1.3.0"
56
53
  },
57
54
  "repository": {
58
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
- fs = require('fs'),
5
- NYC = require('../'),
6
- path = require('path'),
7
- rimraf = require('rimraf'),
8
- sinon = require('sinon'),
9
- spawn = require('child_process').spawn
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
- cwd: process.cwd()
98
- }),
99
- proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
100
- cwd: process.cwd(),
101
- env: process.env,
102
- stdio: 'inherit'
103
- }),
104
- start = fs.readdirSync(nyc.tmpDirectory()).length
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,15 +130,15 @@ describe('nyc', function () {
130
130
 
131
131
  it('handles corrupt JSON files', function (done) {
132
132
  var nyc = new NYC({
133
- cwd: process.cwd()
134
- }),
135
- proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
136
- cwd: process.cwd(),
137
- env: process.env,
138
- stdio: 'inherit'
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
- fs.writeFileSync('./nyc_output/bad.json', '}', 'utf-8')
141
+ fs.writeFileSync('./.nyc_output/bad.json', '}', 'utf-8')
142
142
 
143
143
  proc.on('close', function () {
144
144
  nyc.report(
@@ -155,6 +155,37 @@ describe('nyc', function () {
155
155
  )
156
156
  })
157
157
  })
158
+
159
+ it('handles multiple reporters', function (done) {
160
+ var reporters = ['text-summary', 'text-lcov']
161
+ var incr = 0
162
+ var nyc = new NYC({
163
+ cwd: process.cwd(),
164
+ reporter: reporters
165
+ })
166
+ var proc = spawn(process.execPath, ['./test/fixtures/sigint.js'], {
167
+ cwd: process.cwd(),
168
+ env: process.env,
169
+ stdio: 'inherit'
170
+ })
171
+
172
+ proc.on('close', function () {
173
+ nyc.report(
174
+ {
175
+ add: function (report) {}
176
+ },
177
+ {
178
+ add: function (reporter) {
179
+ incr += !!~reporters.indexOf(reporter)
180
+ },
181
+ write: function () {
182
+ incr.should.eql(reporters.length)
183
+ return done()
184
+ }
185
+ }
186
+ )
187
+ })
188
+ })
158
189
  })
159
190
 
160
191
  describe('.istanbul.yml configuration', function () {