File tree Expand file tree Collapse file tree 17 files changed +174
-33
lines changed Expand file tree Collapse file tree 17 files changed +174
-33
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ async function main () {
4343 NYC_CWD : process . cwd ( )
4444 }
4545
46+ /* istanbul ignore else */
4647 if ( argv [ 'babel-cache' ] === false ) {
4748 // babel's cache interferes with some configurations, so is
4849 // disabled by default. opt in by setting babel-cache=true.
@@ -103,6 +104,6 @@ async function main () {
103104
104105/* istanbul ignore next: the error branch should be unreachable */
105106main ( ) . catch ( error => {
106- console . log ( 'nyc error:' , error )
107+ console . error ( error . message )
107108 process . exit ( 1 )
108109} )
Original file line number Diff line number Diff line change @@ -48,8 +48,7 @@ function coverageFinder () {
4848
4949class NYC {
5050 constructor ( config ) {
51- config = config || { }
52- this . config = config
51+ this . config = { ...config }
5352
5453 this . subprocessBin = config . subprocessBin || path . resolve ( __dirname , './bin/nyc.js' )
5554 this . _tempDirectory = config . tempDirectory || config . tempDir || './.nyc_output'
@@ -151,7 +150,7 @@ class NYC {
151150 compact : this . config . compact ,
152151 preserveComments : this . config . preserveComments ,
153152 esModules : this . config . esModules ,
154- plugins : this . config . parserPlugins
153+ parserPlugins : this . config . parserPlugins
155154 } )
156155 }
157156
@@ -365,7 +364,6 @@ class NYC {
365364
366365 writeCoverageFile ( ) {
367366 var coverage = coverageFinder ( )
368- if ( ! coverage ) return
369367
370368 // Remove any files that should be excluded but snuck into the coverage
371369 Object . keys ( coverage ) . forEach ( function ( absFile ) {
Original file line number Diff line number Diff line change 11const NYC = require ( '../../index.js' )
22const path = require ( 'path' )
33const { promisify } = require ( 'util' )
4+ const resolveFrom = require ( 'resolve-from' )
45const rimraf = promisify ( require ( 'rimraf' ) )
56const { cliWrapper, setupOptions } = require ( './helpers.js' )
67
@@ -49,5 +50,12 @@ exports.handler = cliWrapper(async argv => {
4950 }
5051
5152 const nyc = new NYC ( argv )
53+ if ( ! argv . useSpawnWrap ) {
54+ nyc . require . forEach ( requireModule => {
55+ const mod = resolveFrom . silent ( nyc . cwd , requireModule ) || requireModule
56+ require ( mod )
57+ } )
58+ }
59+
5260 await nyc . instrumentAllFiles ( argv . input , argv . output )
5361} )
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ const fns = [
4444 'writeFile'
4545]
4646fns . forEach ( fn => {
47+ /* istanbul ignore else: all functions exist on OSX */
4748 if ( fs [ fn ] ) {
4849 module . exports [ fn ] = promisify ( fs [ fn ] )
4950 }
Original file line number Diff line number Diff line change @@ -5,9 +5,6 @@ function InstrumenterIstanbul (options) {
55 const convertSourceMap = require ( 'convert-source-map' )
66 const mergeSourceMap = require ( 'merge-source-map' )
77
8- const { plugins } = options
9- const configPlugins = plugins ? { plugins } : { }
10-
118 const instrumenter = createInstrumenter ( {
129 autoWrap : true ,
1310 coverageVariable : '__coverage__' ,
@@ -17,7 +14,7 @@ function InstrumenterIstanbul (options) {
1714 produceSourceMap : options . produceSourceMap ,
1815 ignoreClassMethods : options . ignoreClassMethods ,
1916 esModules : options . esModules ,
20- ... configPlugins
17+ parserPlugins : options . parserPlugins
2118 } )
2219
2320 return {
Original file line number Diff line number Diff line change 11const NYC = require ( '../index.js' )
22
3- let config = { }
4- if ( process . env . NYC_CONFIG ) {
5- config = JSON . parse ( process . env . NYC_CONFIG )
6- }
3+ const config = JSON . parse (
4+ process . env . NYC_CONFIG ||
5+ /* istanbul ignore next */ '{}'
6+ )
7+
78config . isChildProcess = true
89
910config . _processInfo = {
@@ -18,11 +19,7 @@ if (process.env.NYC_PROCESSINFO_EXTERNAL_ID) {
1819}
1920
2021if ( process . env . NYC_CONFIG_OVERRIDE ) {
21- const override = JSON . parse ( process . env . NYC_CONFIG_OVERRIDE )
22- config = {
23- ...config ,
24- ...override
25- }
22+ Object . assign ( config , JSON . parse ( process . env . NYC_CONFIG_OVERRIDE ) )
2623 process . env . NYC_CONFIG = JSON . stringify ( config )
2724}
2825
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const isWindows = require ( 'is-windows' ) ( )
4+
5+ module . exports = {
6+ exclude : [
7+ 'coverage' ,
8+ 'self-coverage' ,
9+ 'test/fixtures/coverage.js' ,
10+ 'test/build/*' ,
11+ 'test/src/*' ,
12+ 'test/nyc.js' ,
13+ 'test/process-args.js' ,
14+ 'test/fixtures/_generateCoverage.js'
15+ ] ,
16+ /* Unknown why we don't get 100% coverage on Windows. */
17+ 'check-coverage' : ! isWindows ,
18+ branches : 100 ,
19+ functions : 100 ,
20+ lines : 100 ,
21+ statements : 100
22+ }
Original file line number Diff line number Diff line change 2222 " bin/*.js" ,
2323 " lib/**/*.js"
2424 ],
25- "nyc" : {
26- "exclude" : [
27- " node_modules" ,
28- " coverage" ,
29- " self-coverage" ,
30- " test/fixtures/coverage.js" ,
31- " test/build/*" ,
32- " test/src/*" ,
33- " test/nyc.js" ,
34- " test/process-args.js" ,
35- " test/fixtures/_generateCoverage.js"
36- ]
37- },
3825 "standard" : {
3926 "ignore" : [
4027 " **/fixtures/**" ,
Original file line number Diff line number Diff line change @@ -930,6 +930,16 @@ exports[`test/nyc-integration.js TAP reports error if input is not a directory >
930930
931931`
932932
933+ exports [ `test/nyc-integration.js TAP run-in-context provide coverage for vm.runInContext > stdout 1` ] = `
934+ ---------------|---------|----------|---------|---------|-------------------
935+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
936+ ---------------|---------|----------|---------|---------|-------------------
937+ All files | 100 | 100 | 100 | 100 |
938+ in-context.js | 100 | 100 | 100 | 100 |
939+ ---------------|---------|----------|---------|---------|-------------------
940+
941+ `
942+
933943exports [ `test/nyc-integration.js TAP setting instrument to "false" configures noop instrumenter > must match snapshot 1` ] = `
934944[
935945 [
Original file line number Diff line number Diff line change 1+ 'use strict'
2+ const path = require ( 'path' )
3+ const vm = require ( 'vm' )
4+
5+ vm . runInContext (
6+ '(() => 10)();' ,
7+ vm . createContext ( { } ) ,
8+ path . resolve ( __dirname , 'in-context.js' )
9+ )
You can’t perform that action at this time.
0 commit comments