Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
chore: Modernize lib/instrumenters. (#985)
  • Loading branch information
coreyfarrell committed Feb 5, 2019
1 parent dd48410 commit 8a5e222
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
18 changes: 6 additions & 12 deletions lib/instrumenters/istanbul.js
@@ -1,14 +1,14 @@
'use strict'

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

function InstrumenterIstanbul (cwd, options) {
const plugins = options.plugins
const configPlugins = plugins ? { plugins } : {}

var istanbul = InstrumenterIstanbul.istanbul()
var instrumenter = istanbul.createInstrumenter(Object.assign({
const instrumenter = createInstrumenter(Object.assign({
autoWrap: true,
coverageVariable: '__coverage__',
embedSource: true,
Expand All @@ -20,7 +20,7 @@ function InstrumenterIstanbul (cwd, options) {
}, configPlugins))

return {
instrumentSync: function (code, filename, sourceMap) {
instrumentSync (code, filename, sourceMap) {
var instrumented = instrumenter.instrumentSync(code, filename)
// the instrumenter can optionally produce source maps,
// this is useful for features like remapping stack-traces.
Expand All @@ -39,16 +39,10 @@ function InstrumenterIstanbul (cwd, options) {
}
return instrumented
},
lastFileCoverage: function () {
lastFileCoverage () {
return instrumenter.lastFileCoverage()
}
}
}

InstrumenterIstanbul.istanbul = function () {
InstrumenterIstanbul._istanbul || (InstrumenterIstanbul._istanbul = require('istanbul-lib-instrument'))

return InstrumenterIstanbul._istanbul || (InstrumenterIstanbul._istanbul = require('istanbul'))
}

module.exports = InstrumenterIstanbul
10 changes: 5 additions & 5 deletions lib/instrumenters/noop.js
@@ -1,18 +1,18 @@
var FileCoverage = require('istanbul-lib-coverage').classes.FileCoverage
var readInitialCoverage = require('istanbul-lib-instrument').readInitialCoverage
const { FileCoverage } = require('istanbul-lib-coverage').classes
const { readInitialCoverage } = require('istanbul-lib-instrument')

function NOOP () {
return {
instrumentSync: function (code, filename) {
var extracted = readInitialCoverage(code)
instrumentSync (code, filename) {
const extracted = readInitialCoverage(code)
if (extracted) {
this.fileCoverage = new FileCoverage(extracted.coverageData)
} else {
this.fileCoverage = null
}
return code
},
lastFileCoverage: function () {
lastFileCoverage () {
return this.fileCoverage
}
}
Expand Down

0 comments on commit 8a5e222

Please sign in to comment.