diff --git a/index.js b/index.js index c9cdd8819..87ada2daf 100755 --- a/index.js +++ b/index.js @@ -79,6 +79,7 @@ function NYC (config) { }.bind(this), {}) this.hookRunInContext = config.hookRunInContext + this.hookRunInThisContext = config.hookRunInThisContext this.fakeRequire = null this.processInfo = new ProcessInfo(config && config._processInfo) @@ -311,6 +312,9 @@ NYC.prototype._wrapRequire = function () { NYC.prototype._addOtherHooks = function () { if (this.hookRunInContext) { + this._addHook('RunInContext') + } + if (this.hookRunInThisContext) { this._addHook('RunInThisContext') } } diff --git a/lib/config-util.js b/lib/config-util.js index 89a396d1c..2c55a3a11 100644 --- a/lib/config-util.js +++ b/lib/config-util.js @@ -173,6 +173,12 @@ Config.buildYargs = function (cwd) { global: false }) .option('hook-run-in-context', { + default: true, + type: 'boolean', + description: 'should nyc wrap vm.runInContext?', + global: false + }) + .option('hook-run-in-this-context', { default: true, type: 'boolean', description: 'should nyc wrap vm.runInThisContext?', diff --git a/package.json b/package.json index a837722f0..cbdd6f6a5 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "foreground-child": "^1.5.3", "glob": "^7.0.6", "istanbul-lib-coverage": "^1.1.1", - "istanbul-lib-hook": "^1.0.7", + "istanbul-lib-hook": "^1.1.0", "istanbul-lib-instrument": "^1.8.0", "istanbul-lib-report": "^1.1.1", "istanbul-lib-source-maps": "^1.2.1",