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.27 to 0.1.28

test/cli/sample-project/node_modules/post-require/hook.js

2

index.js

@@ -108,3 +108,3 @@ /*

//undocumented
_yuiLoadHook: require('./lib/util/yui-load-hook').getPostLoadHook,
_yuiLoadHook: require('./lib/util/yui-load-hook'),
//undocumented

@@ -111,0 +111,0 @@ TreeSummarizer: require('./lib/util/tree-summarizer'),

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

formatOption('--hook-run-in-context', 'hook vm.runInThisContext in addition to require (supports RequireJS), defaults to false'),
formatOption('--post-require-hook <file>', 'JS module that exports a function for post-require processing'),
formatOption('--report <report-type>', 'report type, one of html, lcov, lcovonly, none, defaults to lcov (= lcov.info + HTML)'),

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

'self-test': Boolean,
'hook-run-in-context': Boolean
'hook-run-in-context': Boolean,
'post-require-hook': path
},

@@ -123,7 +125,15 @@ opts = nopt(config, { v : '--verbose' }, args, 0),

transformer = instrumenter.instrumentSync.bind(instrumenter),
hookOpts = { verbose: opts.verbose };
hookOpts = { verbose: opts.verbose },
postLoadHookFile;
if (opts.yui) { //EXPERIMENTAL code: do not rely on this in anyway until the docs say it is allowed
hookOpts.postLoadHook = require('../../util/yui-load-hook').getPostLoadHook(matchFn, transformer, opts.verbose);
if (opts['post-require-hook']) {
postLoadHookFile = path.resolve(opts['post-require-hook']);
} else if (opts.yui) { //EXPERIMENTAL code: do not rely on this in anyway until the docs say it is allowed
postLoadHookFile = path.resolve(__dirname, '../../util/yui-load-hook');
}
if (postLoadHookFile) {
if (opts.verbose) { console.log('Use post-load-hook: ' + postLoadHookFile); }
hookOpts.postLoadHook = require(postLoadHookFile)(matchFn, transformer, opts.verbose);
}
if (opts['self-test']) {

@@ -130,0 +140,0 @@ hook.unloadRequireCache(matchFn);

@@ -86,2 +86,4 @@ /*

* @param {Boolean} [options.verbose] write a line to standard error every time the transformer is called
* @param {Function} [options.postLoadHook] a function that is called with the name of the file being
* required. This is called after the require is processed irrespective of whether it was transformed.
*/

@@ -88,0 +90,0 @@ function hookRequire(matcher, transformer, options) {

@@ -11,42 +11,40 @@ /*

module.exports = {
getPostLoadHook: function (matchFn, transformFn, verbose) {
return function (file) {
if (!file.match(yuiRegexp)) {
return;
}
var YMain = require(file),
YUI,
loaderFn,
origGet;
module.exports = function (matchFn, transformFn, verbose) {
return function (file) {
if (!file.match(yuiRegexp)) {
return;
}
var YMain = require(file),
YUI,
loaderFn,
origGet;
if (YMain.YUI) {
YUI = YMain.YUI;
loaderFn = YUI.Env && YUI.Env.mods && YUI.Env.mods['loader-base'] ? YUI.Env.mods['loader-base'].fn : null;
if (!loaderFn) { return; }
if (verbose) { console.log('Applying YUI load post-hook'); }
YUI.Env.mods['loader-base'].fn = function (Y) {
loaderFn.call(null, Y);
origGet = Y.Get._exec;
Y.Get._exec = function (data, url, cb) {
if (matchFn(url) || matchFn(path.resolve(url))) { //allow for relative paths as well
if (verbose) {
console.log('Transforming [' + url + ']');
}
try {
data = transformFn(data, url);
} catch (ex) {
console.error('Error transforming: ' + url + ' return original code');
console.error(ex.message || ex);
if (ex.stack) { console.error(ex.stack); }
}
if (YMain.YUI) {
YUI = YMain.YUI;
loaderFn = YUI.Env && YUI.Env.mods && YUI.Env.mods['loader-base'] ? YUI.Env.mods['loader-base'].fn : null;
if (!loaderFn) { return; }
if (verbose) { console.log('Applying YUI load post-hook'); }
YUI.Env.mods['loader-base'].fn = function (Y) {
loaderFn.call(null, Y);
origGet = Y.Get._exec;
Y.Get._exec = function (data, url, cb) {
if (matchFn(url) || matchFn(path.resolve(url))) { //allow for relative paths as well
if (verbose) {
console.log('Transforming [' + url + ']');
}
return origGet.call(Y, data, url, cb);
};
return Y;
try {
data = transformFn(data, url);
} catch (ex) {
console.error('Error transforming: ' + url + ' return original code');
console.error(ex.message || ex);
if (ex.stack) { console.error(ex.stack); }
}
}
return origGet.call(Y, data, url, cb);
};
}
};
}
return Y;
};
}
};
};
{
"name": "istanbul",
"version": "0.1.27",
"version": "0.1.28",
"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",

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

"scripts": {
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json lib/*js lib/command/*js lib/report/*js lib/store/*js lib/util/*js",
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json lib/*js lib/command/*js lib/report/*js lib/store/*js lib/util/*js test/*js test/instrumentation/*js test/cli/*js test/other/*js",
"test": "test/run.js",

@@ -19,0 +19,0 @@ "posttest": "node ./lib/cli.js check-coverage --statements 95 --branches 80",

/*jslint nomen: true */
var path = require('path'),
fs = require('fs'),
util = require('util'),
cp = require('child_process'),

@@ -6,0 +5,0 @@ Module = require('module'),

/*jslint nomen: true */
var path = require('path'),
helper = require('../cli-helper');
var helper = require('../cli-helper');

@@ -5,0 +4,0 @@ module.exports = {

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

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

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

@@ -13,5 +13,3 @@ /*jslint nomen: true */

Collector = require('../../lib/collector'),
existsSync = fs.existsSync || path.existsSync,
filename,
cov;
existsSync = fs.existsSync || path.existsSync;

@@ -23,3 +21,3 @@ module.exports = {

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

@@ -37,4 +35,3 @@ });

obj,
collector = new Collector(),
numFiles;
collector = new Collector();

@@ -41,0 +38,0 @@ obj = JSON.parse(fs.readFileSync(file, 'utf8'));

/*jslint nomen: true */
var path = require('path'),
fs = require('fs'),
vm = require('vm'),
rimraf = require('rimraf'),

@@ -128,3 +127,17 @@ mkdirp = require('mkdirp'),

});
},
"should apply post-require-hook correctly": function (test) {
helper.setOpts({ lazyHook : true });
run([ 'test/run.js', '-v', '-x', '**/foo.js', '--post-require-hook', 'node_modules/post-require/hook.js' ], function (results) {
test.ok(results.succeeded());
test.ok(results.grepError(/PRH: MatchFn was a function/));
test.ok(results.grepError(/PRH: TransformFn was a function/));
test.ok(results.grepError(/PRH: Verbose was true/));
//yes, post require hook must be called always even when a file is not covered
test.ok(results.grepError(/PRH: Saw foo\.js/));
//and, of course, for covered files as well
test.ok(results.grepError(/PRH: Saw bar\.js/));
test.done();
});
}
};

@@ -13,5 +13,3 @@ /*jslint nomen: true */

Collector = require('../../lib/collector'),
existsSync = fs.existsSync || path.existsSync,
filename,
cov;
existsSync = fs.existsSync || path.existsSync;

@@ -23,3 +21,3 @@ module.exports = {

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

@@ -107,3 +105,3 @@ });

copy[mangled] = obj[k];
test.ok(mangled != k); //verify something _did_ get mangled
test.ok(mangled !== k); //verify something _did_ get mangled
test.ok(copy[mangled].code);

@@ -110,0 +108,0 @@ });

@@ -13,5 +13,3 @@ /*jslint nomen: true */

Collector = require('../../lib/collector'),
existsSync = fs.existsSync || path.existsSync,
filename,
cov;
existsSync = fs.existsSync || path.existsSync;

@@ -23,3 +21,3 @@ module.exports = {

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

@@ -26,0 +24,0 @@ });

@@ -13,5 +13,3 @@ /*jslint nomen: true */

Collector = require('../../lib/collector'),
existsSync = fs.existsSync || path.existsSync,
filename,
cov;
existsSync = fs.existsSync || path.existsSync;

@@ -23,3 +21,3 @@ module.exports = {

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

@@ -26,0 +24,0 @@ });

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

helper.resetOpts();
runCover([ 'test/run.js', '--report', 'none' ], function (results) {
runCover([ 'test/run.js', '--report', 'none' ], function (/* results */) {
cb();

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

/*jslint nomen: true */
/*global __coverage__ */
var Instrumenter = require('../lib/instrumenter'),

@@ -77,3 +76,4 @@ vm = require('vm'),

var expectError = opts.expectError,
coverageVariable = typeof opts.coverageVariable === 'undefined' ? '$$coverage$$' : opts.coverageVariable, //exercise the case where RE substitutions for the preamble have $ signs
//exercise the case where RE substitutions for the preamble have $ signs
coverageVariable = typeof opts.coverageVariable === 'undefined' ? '$$coverage$$' : opts.coverageVariable,
ps = opts.embedSource || false,

@@ -101,7 +101,7 @@ verifier,

var wrappedCode = '(function (args) { var output;\n' + generated + '\nreturn output;\n})',
fn,
output;
fn;
global[coverageVariable] = undefined;
fn = vm.runInThisContext(wrappedCode, __filename);
verifier = new Verifier({ debug: opts.debug, file: file, fn: fn, code: codeArray, generatedCode: generated, coverageVariable: coverageVariable });
verifier = new Verifier({ debug: opts.debug, file: file, fn: fn, code: codeArray,
generatedCode: generated, coverageVariable: coverageVariable });
if (opts.debug) {

@@ -108,0 +108,0 @@ console.log('================== Original ============================================');

@@ -6,2 +6,3 @@ /*jslint nomen: true */

/*jshint maxlen: 500 */
module.exports = {

@@ -8,0 +9,0 @@ "with a simple do-while": {

@@ -6,2 +6,3 @@ /*jslint nomen: true */

/*jshint maxlen: 500 */
module.exports = {

@@ -8,0 +9,0 @@ "with a simple expression": {

@@ -6,2 +6,3 @@ /*jslint nomen: true */

/*jshint maxlen: 500 */
module.exports = {

@@ -8,0 +9,0 @@ "with a simple for-in": {

@@ -6,2 +6,3 @@ /*jslint nomen: true */

/*jshint maxlen: 500 */
module.exports = {

@@ -8,0 +9,0 @@ "with a simple function": {

@@ -5,2 +5,4 @@ /*jslint nomen: true */

verifier;
/*jshint maxlen: 500 */
module.exports = {

@@ -7,0 +9,0 @@ "with a simple if": {

/*jslint nomen: true */
var helper = require('../helper'),
Instrumenter = require('../../lib/instrumenter'),
path = require('path'),
code,

@@ -6,0 +5,0 @@ verifier;

@@ -5,2 +5,4 @@ /*jslint nomen: true */

verifier;
/*jshint maxlen: 500 */
module.exports = {

@@ -7,0 +9,0 @@ "with an empty switch": {

@@ -6,2 +6,3 @@ /*jslint nomen: true */

/*jshint maxlen: 500 */
module.exports = {

@@ -8,0 +9,0 @@ "with a simple while": {

@@ -5,6 +5,6 @@ /*jslint nomen: true */

matcher = function (file) { return file.indexOf('foo.js') > 0; },
transformer = function (code, file) { return 'module.exports.bar = function () { return "bar"; };'; },
transformer2 = function (code, file) { return 'module.exports.blah = function () { return "blah"; };'; },
badTransformer = function (code, file) { throw "Boo!"; },
scriptTransformer = function (code, file) { return '(function () { return 42; }());'; };
transformer = function () { return 'module.exports.bar = function () { return "bar"; };'; },
transformer2 = function () { return 'module.exports.blah = function () { return "blah"; };'; },
badTransformer = function () { throw "Boo!"; },
scriptTransformer = function () { return '(function () { return 42; }());'; };

@@ -11,0 +11,0 @@ module.exports = {

@@ -78,6 +78,6 @@ /*jslint nomen: true */

"should be able to register a new store": function (test) {
function NStore(opts) {
function NStore() {
}
NStore.prototype = {
set: function (file, content) { return 'x'; }
set: function (/* file, content */) { return 'x'; }
};

@@ -94,3 +94,3 @@ NStore.TYPE = 'nstore';

"should not be able to register an invalid store": function (test) {
function NStore(opts) {}
function NStore() {}
test.throws(function () {

@@ -112,3 +112,3 @@ Store.register(NStore);

"should require overriding of all overrideables": function (test) {
function NStore(opts) {}
function NStore() {}
NStore.TYPE = 'nstore';

@@ -115,0 +115,0 @@ util.inherits(NStore, Store);

#!/usr/bin/env node
var path = require('path'),
nodeunit = require('nodeunit'),
var nodeunit = require('nodeunit'),
mkdirp = require('mkdirp'),

@@ -6,0 +5,0 @@ loader = require('./loader'),

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