Comparing version 1.0.0 to 1.1.0
43
index.js
@@ -8,4 +8,3 @@ var vm = require('vm') | ||
var reporter = new istanbul.Reporter() | ||
var sandboxes = [] | ||
var config = { report: true } | ||
var coverageObjects = [] | ||
@@ -15,7 +14,7 @@ process.on('exit', function onExit() { | ||
if (config.report) { | ||
sandboxes.map(function mapSandbox(sandbox) { | ||
collector.add(sandbox.__coverage__) | ||
}) | ||
coverageObjects.map(function mapSandbox(coverageObject) { | ||
collector.add(coverageObject) | ||
}) | ||
if (coverageObjects.length > 0) { | ||
reporter.addAll([ 'lcov', 'clover' ]) | ||
@@ -27,26 +26,20 @@ reporter.write(collector, sync, function anonymous() {}) | ||
module.exports = { | ||
getScript: function getScript(filename) { | ||
var code = fs.readFileSync(filename).toString() | ||
var instrumentedCode = instrumenter.instrumentSync(code, filename) | ||
var script = new vm.Script(instrumentedCode, { filename: filename }) | ||
script.isInstrumented = true | ||
return script | ||
}, | ||
runInContext: function runInContext(filename, context, fn) { | ||
var code = fs.readFileSync(filename).toString() | ||
var instrumentedCode = config.report ? | ||
instrumenter.instrumentSync(code, filename) : code | ||
var script = this.getScript(filename) | ||
return this.runScriptInContext(script, context, fn) | ||
}, | ||
runScriptInContext: function runScriptInContext(script, context, fn) { | ||
var sandbox = vm.createContext(context) | ||
var script = new vm.Script(instrumentedCode, { filename: filename }) | ||
script.runInContext(sandbox) | ||
sandboxes.push(sandbox) | ||
if (fn) { | ||
fn(sandbox) | ||
} | ||
if (script.isInstrumented) coverageObjects.push(sandbox.__coverage__) | ||
if (fn) fn(sandbox) | ||
return sandbox | ||
}, | ||
config: function configFn(additionalOptions) { | ||
var option | ||
if (additionalOptions) { | ||
for (option in additionalOptions) { | ||
if (additionalOptions.hasOwnProperty(option)) { | ||
config[option] = additionalOptions[option] | ||
} | ||
} | ||
} | ||
}, | ||
} |
@@ -44,3 +44,3 @@ { | ||
], | ||
"version": "1.0.0" | ||
"version": "1.1.0" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2644
37