Skip to content

Commit

Permalink
fix: Honor eager setting (false by default) (#1179)
Browse files Browse the repository at this point in the history
This delays loading of istanbul-lib-instrument until it is needed.
  • Loading branch information
coreyfarrell authored Sep 24, 2019
1 parent 0fc93d9 commit c18fb0a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/instrumenters/istanbul.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { createInstrumenter } = require('istanbul-lib-instrument')
const convertSourceMap = require('convert-source-map')
const mergeSourceMap = require('merge-source-map')

function InstrumenterIstanbul (options) {
const { createInstrumenter } = require('istanbul-lib-instrument')
const convertSourceMap = require('convert-source-map')
const mergeSourceMap = require('merge-source-map')

const { plugins } = options
const configPlugins = plugins ? { plugins } : {}

Expand All @@ -28,6 +28,7 @@ function InstrumenterIstanbul (options) {
// TODO: test source-map merging logic.
if (options.produceSourceMap) {
var lastSourceMap = instrumenter.lastSourceMap()
/* istanbul ignore else */
if (lastSourceMap) {
if (sourceMap) {
lastSourceMap = mergeSourceMap(
Expand Down
4 changes: 3 additions & 1 deletion lib/instrumenters/noop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { readInitialCoverage } = require('istanbul-lib-instrument')
'use strict'

function NOOP () {
const { readInitialCoverage } = require('istanbul-lib-instrument')

return {
instrumentSync (code, filename) {
const extracted = readInitialCoverage(code)
Expand Down
16 changes: 16 additions & 0 deletions tap-snapshots/test-eager.js-TAP.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* IMPORTANT
* This snapshot file is auto-generated, but designed for humans.
* It should be checked into source control and tracked carefully.
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/eager.js TAP eager disabled by default > stdout 1`] = `
0
`

exports[`test/eager.js TAP eager enabled > stdout 1`] = `
1
`
30 changes: 30 additions & 0 deletions test/eager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict'

const path = require('path')

const t = require('tap')

const { testSuccess } = require('./helpers')

const cwd = path.resolve(__dirname, 'fixtures')

t.test('eager disabled by default', t => testSuccess(t, {
args: [
'--silent=true',
'--exclude=eager.js',
process.execPath,
'./eager.js'
],
cwd
}))

t.test('eager enabled', t => testSuccess(t, {
args: [
'--silent=true',
'--eager=true',
'--exclude=eager.js',
process.execPath,
'./eager.js'
],
cwd
}))
5 changes: 5 additions & 0 deletions test/fixtures/eager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node
'use strict'

const lib = require.resolve('istanbul-lib-instrument')
console.log(Object.keys(require.cache).filter(s => s === lib).length)

0 comments on commit c18fb0a

Please sign in to comment.