Permalink
Browse files

Make hooking of vm.runInThisContext conditional, based on --hook-run-…

…in-context switch
  • Loading branch information...
1 parent 2693413 commit 2c4bf570eb1d0a14546302f2a2a8accf3d2cf5a5 @gotwarlost committed Jan 3, 2013
Showing with 7 additions and 3 deletions.
  1. +6 −2 lib/command/common/run-with-cover.js
  2. +1 −1 test/cli/test-cover-command.js
@@ -24,6 +24,7 @@ function usage(arg0, command) {
formatOption('--root <path> ', 'the root path to look for files to instrument, defaults to .'),
formatOption('-x <exclude-pattern> [-x <exclude-pattern>]', 'one or more fileset patterns e.g. "**/vendor/**"'),
formatOption('--[no-]default-excludes', 'apply default excludes [ **/node_modules/**, **/test/**, **/tests/** ], defaults to true'),
+ formatOption('--hook-run-in-context', 'hook vm.runInThisContext in addition to require (supports RequireJS), defaults to false'),
formatOption('--report <report-type>', 'report type, one of html, lcov, lcovonly, none, defaults to lcov (= lcov.info + HTML)'),
formatOption('--dir <report-dir>', 'report directory, defaults to ./coverage'),
formatOption('--print <type>', 'type of report to print to console, one of summary (default), detail, both or none'),
@@ -43,7 +44,8 @@ function run(args, commandName, enableHooks, callback) {
yui: Boolean,
'default-excludes': Boolean,
print: String,
- 'self-test': Boolean
+ 'self-test': Boolean,
+ 'hook-run-in-context': Boolean
},
opts = nopt(config, { v : '--verbose' }, args, 0),
cmdAndArgs = opts.argv.remain,
@@ -125,7 +127,9 @@ function run(args, commandName, enableHooks, callback) {
hook.unloadRequireCache(matchFn);
}
// runInThisContext is used by RequireJS [issue #23]
- hook.hookRunInThisContext(matchFn, transformer, hookOpts);
+ if (opts['hook-run-in-context']) {
+ hook.hookRunInThisContext(matchFn, transformer, hookOpts);
+ }
hook.hookRequire(matchFn, transformer, hookOpts);
process.once('exit', function () {
var file = path.resolve(reportingDir, 'coverage.json'),
@@ -112,7 +112,7 @@ module.exports = {
},
"should work with RequireJS and AMD modules": function (test) {
helper.setOpts({ lazyHook : true });
- run([ 'test/amd-run.js', '-v' ], function (results) {
+ run([ 'test/amd-run.js', '-v', '--hook-run-in-context' ], function (results) {
test.ok(results.succeeded());
test.ok(results.grepError(/Module load hook:/));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov.info')));

0 comments on commit 2c4bf57

Please sign in to comment.