Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Honor eager setting (false by default) #1179

Merged
merged 1 commit into from Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/instrumenters/istanbul.js
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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)