Comparing version 4.0.0-alpha to 4.0.0
@@ -8,11 +8,5 @@ #!/usr/bin/env node | ||
if (process.env.NYC_CWD) { | ||
;(new NYC()).wrap() | ||
if (process.env.NYC_BABEL === '1') { | ||
require.main.paths.push(path.resolve(process.env.NYC_CWD, '/node_modules')) | ||
try { | ||
require('babel-core/register') | ||
} catch (e) { | ||
require('babel-register') | ||
} | ||
} | ||
;(new NYC({ | ||
require: process.env.NYC_REQUIRE.split(',') | ||
})).wrap() | ||
@@ -84,7 +78,6 @@ // make sure we can run coverage on | ||
}) | ||
.option('b', { | ||
alias: 'babel', | ||
default: false, | ||
type: 'boolean', | ||
describe: "should nyc include babel's require hook? (you must add babel as a dependency to your project)" | ||
.option('i', { | ||
alias: 'require', | ||
default: [], | ||
describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill.' | ||
}) | ||
@@ -95,2 +88,3 @@ .help('h') | ||
.example('$0 npm test', 'instrument your tests with coverage') | ||
.example('$0 --require babel-core/polyfill --require babel-core/register npm test', 'instrument your tests with coverage and babel') | ||
.example('$0 report --reporter=text-lcov', 'output lcov report after running your tests') | ||
@@ -124,6 +118,7 @@ .epilog('visit http://git.io/vTJJB for list of available reporters') | ||
if (argv.all) nyc.addAllFiles() | ||
if (!Array.isArray(argv.require)) argv.require = [argv.require] | ||
sw([__filename], { | ||
NYC_CWD: process.cwd(), | ||
NYC_BABEL: argv.babel ? '1' : '0' | ||
NYC_REQUIRE: argv.require.join(',') | ||
}) | ||
@@ -130,0 +125,0 @@ |
## Change Log | ||
### v4.0.0 (2015/11/29 10:13 -07:00) | ||
- [#58](https://github.com/bcoe/nyc/pull/58) adds support for Babel (@bcoe) | ||
### v3.2.2 (2015/09/11 22:02 -07:00) | ||
@@ -4,0 +8,0 @@ |
16
index.js
@@ -22,3 +22,4 @@ /* global __coverage__ */ | ||
istanbul: require('istanbul'), | ||
sourceMapCache: new SourceMapCache() | ||
sourceMapCache: new SourceMapCache(), | ||
require: [] | ||
}, opts) | ||
@@ -28,5 +29,7 @@ | ||
// you can specify config in the nyc stanza of package.json. | ||
var config = require(path.resolve(this.cwd, './package.json')).config || {} | ||
config = config.nyc || {} | ||
// load exclude stanza from config. | ||
this.exclude = config.exclude || ['node_modules[\/\\\\]', 'test[\/\\\\]', 'test\\.js'] | ||
@@ -38,2 +41,5 @@ if (!Array.isArray(this.exclude)) this.exclude = [this.exclude] | ||
// require extensions can be provided as config in package.json. | ||
this.require = config.require ? config.require : this.require | ||
this.instrumenter = this._createInstrumenter() | ||
@@ -43,2 +49,9 @@ this._createOutputDirectory() | ||
NYC.prototype._loadAdditionalModules = function () { | ||
require.main.paths.push(path.resolve(this.cwd, '/node_modules')) | ||
this.require.forEach(function (r) { | ||
require(r) | ||
}) | ||
} | ||
NYC.prototype._createInstrumenter = function () { | ||
@@ -181,2 +194,3 @@ var configFile = path.resolve(this.cwd, './.istanbul.yml') | ||
this._wrapExit() | ||
this._loadAdditionalModules() | ||
return this | ||
@@ -183,0 +197,0 @@ } |
{ | ||
"name": "nyc", | ||
"version": "4.0.0-alpha", | ||
"version": "4.0.0", | ||
"description": "a code coverage tool that works well with subprocesses.", | ||
"main": "index.js", | ||
"scripts": { | ||
"istanbul": "istanbul", | ||
"pretest": "standard", | ||
"test": " tap --coverage ./test/*.js" | ||
"test": "tap --coverage ./test/*.js" | ||
}, | ||
@@ -11,0 +10,0 @@ "bin": { |
@@ -39,6 +39,25 @@ # nyc | ||
## Support For Babel ES2015 | ||
## Support For Babel/ES2015 | ||
nyc is the easiest way to add ES2015 support to your project. | ||
nyc is the easiest way to add ES2015 support to your project: | ||
1. install the appropriate babel dependencies for your project (`npm i babel-core babel-preset-es2015 --save`). | ||
2. create a `.babelrc` file: | ||
```json | ||
{ | ||
"presets": ["es2015"] | ||
} | ||
``` | ||
3. install nyc, and run it with the appropriate `--require` flags: | ||
```sh | ||
nyc --require babel-core/register mocha | ||
``` | ||
nyc uses source-maps to map coverage information back to the appropriate lines of the pre-transpiled code: | ||
<img width="350" src="screen.png"> | ||
## Checking Coverage | ||
@@ -108,2 +127,9 @@ | ||
## Require additional modules | ||
The `--require` flag can be provided to `nyc` to indicate that additional | ||
modules should be required in the subprocess collecting coverage: | ||
`nyc --require babel-core/register --require babel-polyfill mocha` | ||
## Configuring Istanbul | ||
@@ -110,0 +136,0 @@ |
@@ -17,2 +17,26 @@ /* global describe, it */ | ||
describe('babel', function () { | ||
it('collects coverage when the babel require hook is installed', function (done) { | ||
var nyc = (new NYC({ | ||
cwd: process.cwd() | ||
})).wrap() | ||
delete require.cache[require.resolve('babel-core/register')] | ||
require('babel-core/register') | ||
require('./fixtures/es6-not-loaded.js') | ||
nyc.writeCoverageFile() | ||
var reports = _.filter(nyc._loadReports(), function (report) { | ||
return report['./test/fixtures/es6-not-loaded.js'] | ||
}) | ||
var report = reports[0]['./test/fixtures/es6-not-loaded.js'] | ||
reports.length.should.equal(1) | ||
report.s['1'].should.equal(1) | ||
report.s['2'].should.equal(1) | ||
return done() | ||
}) | ||
}) | ||
describe('cwd', function () { | ||
@@ -284,3 +308,3 @@ function afterEach () { | ||
describe('addAllFiles', function () { | ||
/* it('outputs an empty coverage report for all files that are not excluded', function (done) { | ||
it('outputs an empty coverage report for all files that are not excluded', function (done) { | ||
var nyc = (new NYC()) | ||
@@ -298,3 +322,3 @@ nyc.addAllFiles() | ||
return done() | ||
})*/ | ||
}) | ||
@@ -320,26 +344,2 @@ it('tracks coverage appropriately once the file is required', function (done) { | ||
}) | ||
describe('babel', function () { | ||
it('collects coverage when the babel require hook is installed', function (done) { | ||
var nyc = (new NYC({ | ||
cwd: process.cwd() | ||
})).wrap() | ||
delete require.cache[require.resolve('babel-core/register')] | ||
require('babel-core/register') | ||
require('./fixtures/es6-not-loaded.js') | ||
nyc.writeCoverageFile() | ||
var reports = _.filter(nyc._loadReports(), function (report) { | ||
return report['./test/fixtures/es6-not-loaded.js'] | ||
}) | ||
var report = reports[0]['./test/fixtures/not-loaded.js'] | ||
reports.length.should.equal(1) | ||
report.s['1'].should.equal(1) | ||
report.s['2'].should.equal(1) | ||
return done() | ||
}) | ||
}) | ||
}) |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
399403
58
8136
1
180
6