New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nyc

Package Overview
Dependencies
Maintainers
2
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nyc - npm Package Compare versions

Comparing version 3.2.2 to 4.0.0-alpha

.babelrc

17

bin/nyc.js

@@ -9,2 +9,10 @@ #!/usr/bin/env node

;(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')
}
}

@@ -76,2 +84,8 @@ // 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)"
})
.help('h')

@@ -111,3 +125,4 @@ .alias('h', 'help')

sw([__filename], {
NYC_CWD: process.cwd()
NYC_CWD: process.cwd(),
NYC_BABEL: argv.babel ? '1' : '0'
})

@@ -114,0 +129,0 @@

@@ -10,2 +10,3 @@ /* global __coverage__ */

var stripBom = require('strip-bom')
var SourceMapCache = require('./lib/source-map-cache')

@@ -21,3 +22,4 @@ function NYC (opts) {

reporter: 'text',
istanbul: require('istanbul')
istanbul: require('istanbul'),
sourceMapCache: new SourceMapCache()
}, opts)

@@ -56,16 +58,23 @@

NYC.prototype.addFile = function (filename, returnImmediately) {
var instrument = true
var relFile = path.relative(this.cwd, filename)
var instrument = this.shouldInstrumentFile(relFile)
var content = stripBom(fs.readFileSync(filename, 'utf8'))
// only instrument a file if it's not on the exclude list.
for (var i = 0, exclude; (exclude = this.exclude[i]) !== undefined; i++) {
if (exclude.test(relFile)) {
if (returnImmediately) return {}
instrument = false
break
}
if (instrument) {
content = this.instrumenter.instrumentSync(content, './' + relFile)
} else if (returnImmediately) {
return {}
}
var content = stripBom(fs.readFileSync(filename, 'utf8'))
return {
instrument: instrument,
content: content,
relFile: relFile
}
}
NYC.prototype.addContent = function (filename, content) {
var relFile = path.relative(this.cwd, filename)
var instrument = this.shouldInstrumentFile(relFile)
if (instrument) {

@@ -82,2 +91,12 @@ content = this.instrumenter.instrumentSync(content, './' + relFile)

NYC.prototype.shouldInstrumentFile = function (relFile, returnImmediately) {
// only instrument a file if it's not on the exclude list.
for (var i = 0, exclude; (exclude = this.exclude[i]) !== undefined; i++) {
if (exclude.test(relFile)) {
return false
}
}
return true
}
NYC.prototype.addAllFiles = function () {

@@ -104,7 +123,37 @@ var _this = this

// any JS you require should get coverage added.
require.extensions['.js'] = function (module, filename) {
var obj = _this.addFile(filename)
var babelRequireHook = null
var requireHook = function (module, filename) {
// allow babel's compile hoook to compile
// the code -- ignore node_modules, this
// helps avoid cyclical require behavior.
var content = null
if (babelRequireHook && filename.indexOf('node_modules/') === -1) {
babelRequireHook({
_compile: function (compiledSrc) {
_this.sourceMapCache.add(filename, compiledSrc)
content = compiledSrc
}
}, filename)
}
// now instrument the compiled code.
var obj = null
if (content) {
obj = _this.addContent(filename, content)
} else {
obj = _this.addFile(filename, false)
}
module._compile(obj.content, filename)
}
// use a getter and setter to capture any external
// require hooks that are registered, e.g., babel-core/register
require.extensions.__defineGetter__('.js', function () {
return requireHook
})
require.extensions.__defineSetter__('.js', function (value) {
babelRequireHook = value
})
}

@@ -143,3 +192,3 @@

path.resolve(this.tmpDirectory(), './', process.pid + '.json'),
JSON.stringify(coverage),
JSON.stringify(this.sourceMapCache.applySourceMaps(coverage)),
'utf-8'

@@ -146,0 +195,0 @@ )

{
"name": "nyc",
"version": "3.2.2",
"version": "4.0.0-alpha",
"description": "a code coverage tool that works well with subprocesses.",

@@ -8,3 +8,4 @@ "main": "index.js",

"istanbul": "istanbul",
"test": "standard && tap --coverage ./test/nyc-test.js"
"pretest": "standard",
"test": " tap --coverage ./test/*.js"
},

@@ -22,2 +23,7 @@ "bin": {

},
"standard": {
"ignore": [
"**/fixtures/**"
]
},
"keywords": [

@@ -42,2 +48,3 @@ "coverage",

"dependencies": {
"convert-source-map": "^1.1.2",
"foreground-child": "1.3.0",

@@ -50,2 +57,3 @@ "glob": "^5.0.14",

"signal-exit": "^2.1.1",
"source-map": "^0.5.3",
"spawn-wrap": "^1.0.1",

@@ -56,2 +64,4 @@ "strip-bom": "^2.0.0",

"devDependencies": {
"babel-core": "^6.2.1",
"babel-preset-es2015": "^6.1.18",
"chai": "^3.0.0",

@@ -58,0 +68,0 @@ "sinon": "^1.15.3",

@@ -39,2 +39,6 @@ # nyc

## Support For Babel ES2015
nyc is the easiest way to add ES2015 support to your project.
## Checking Coverage

@@ -41,0 +45,0 @@

@@ -283,3 +283,3 @@ /* global describe, it */

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())

@@ -297,3 +297,3 @@ nyc.addAllFiles()

return done()
})
})*/

@@ -305,4 +305,4 @@ it('tracks coverage appropriately once the file is required', function (done) {

require('./fixtures/not-loaded')
nyc.writeCoverageFile()
var reports = _.filter(nyc._loadReports(), function (report) {

@@ -320,2 +320,26 @@ return report['./test/fixtures/not-loaded.js']

})
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()
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc