Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istanbul

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istanbul - npm Package Compare versions

Comparing version 0.1.26 to 0.1.27

test/cli/sample-project/amd/ipsum.js

8

lib/command/common/run-with-cover.js

@@ -27,2 +27,3 @@ /*

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)'),

@@ -47,3 +48,4 @@ formatOption('--dir <report-dir>', 'report directory, defaults to ./coverage'),

print: String,
'self-test': Boolean
'self-test': Boolean,
'hook-run-in-context': Boolean
},

@@ -129,2 +131,6 @@ opts = nopt(config, { v : '--verbose' }, args, 0),

}
// runInThisContext is used by RequireJS [issue #23]
if (opts['hook-run-in-context']) {
hook.hookRunInThisContext(matchFn, transformer, hookOpts);
}
hook.hookRequire(matchFn, transformer, hookOpts);

@@ -131,0 +137,0 @@ process.once('exit', function () {

@@ -37,3 +37,4 @@ /*

originalLoader = Module._extensions['.js'],
originalCreateScript = vm.createScript;
originalCreateScript = vm.createScript,
originalRunInThisContext = vm.runInThisContext;

@@ -143,2 +144,33 @@ function transformFn(matcher, transformer, verbose) {

/**
* hooks `vm.runInThisContext` to return transformed code.
* @method hookRunInThisContext
* @static
* @param matcher {Function(filePath)} a function that is called with the filename passed to `vm.createScript`
* Should return a truthy value when transformations need to be applied to the code, a falsy value otherwise
* @param transformer {Function(code, filePath)} a function called with the original code and the filename passed to
* `vm.createScript`. Should return the transformed code.
* @param options {Object} options Optional.
* @param {Boolean} [options.verbose] write a line to standard error every time the transformer is called
*/
function hookRunInThisContext(matcher, transformer, opts) {
opts = opts || {};
var fn = transformFn(matcher, transformer, opts.verbose);
vm.runInThisContext = function (code, file) {
var ret = fn(code, file);
return originalRunInThisContext(ret.code, file);
};
}
/**
* unhooks vm.runInThisContext, restoring it to its original state.
* @method unhookRunInThisContext
* @static
*/
function unhookRunInThisContext() {
vm.runInThisContext = originalRunInThisContext;
}
module.exports = {

@@ -149,2 +181,4 @@ hookRequire: hookRequire,

unhookCreateScript: unhookCreateScript,
hookRunInThisContext : hookRunInThisContext,
unhookRunInThisContext : unhookRunInThisContext,
unloadRequireCache: unloadRequireCache

@@ -151,0 +185,0 @@ };

8

package.json
{
"name": "istanbul",
"version": "0.1.26",
"version": "0.1.27",
"description": "Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale",

@@ -11,3 +11,4 @@ "keywords": [ "coverage", "code coverage", "JS code coverage", "JS coverage" ],

"Dav Glass <davglass@gmail.com>",
"nowamasa <nowamasa@gmail.com>"
"nowamasa <nowamasa@gmail.com>",
"Miller Medeiros <contact@millermedeiros.com>"
],

@@ -40,3 +41,4 @@ "preferGlobal": true,

"jshint": "*",
"yui-lint": "*"
"yui-lint": "*",
"requirejs": "2.x"
},

@@ -43,0 +45,0 @@ "TODO": [

@@ -112,3 +112,19 @@ /*jslint nomen: true */

});
},
"should work with RequireJS and AMD modules": function (test) {
helper.setOpts({ lazyHook : true });
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')));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'lcov-report')));
test.ok(existsSync(path.resolve(OUTPUT_DIR, 'coverage.json')));
var coverage = JSON.parse(fs.readFileSync(path.resolve(OUTPUT_DIR, 'coverage.json'), 'utf8')),
filtered;
filtered = Object.keys(coverage).filter(function (k) { return k.match(/amd\/lorem/) || k.match(/amd\/ipsum/); });
test.ok(filtered.length === 2);
test.ok(filtered.length === Object.keys(coverage).length);
test.done();
});
}
};
};

@@ -86,3 +86,3 @@ /*jslint nomen: true */

test.ok(existsSync(covFile));
//test.ok(results.grepOutput(/Saving baseline coverage at/));
test.ok(results.grepOutput(/Saving baseline coverage at/));
test.done();

@@ -89,0 +89,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc