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.37 to 0.1.38

4

CHANGELOG.md

@@ -5,2 +5,6 @@ Changelog

<table>
<tr><td>v0.1.38</td><td><ul>
<li>factor out AST instrumentation into own instrumentASTSync method</li>
<li>always set function declaration coverage stats to 1 since every such declaration is "executed" exactly one time by the compiler</li>
</ul></td></tr>
<tr><td>v0.1.37</td><td>--complete-copy flag contrib from @kami, correct strict mode semantics for instrumented functions</td></tr>

@@ -7,0 +11,0 @@ <tr><td>v0.1.36</td><td>real quiet when --print=none specified, add repo URL to package.json, add contributors</td></tr>

72

lib/instrumenter.js

@@ -360,4 +360,28 @@ /*

instrumentSync: function (code, filename) {
var codegenOptions,
program;
var program;
//protect from users accidentally passing in a Buffer object instead
if (typeof code !== 'string') { throw new Error('Code must be string'); }
if (code.charAt(0) === '#') { //shebang, 'comment' it out, won't affect syntax tree locations for things we care about
code = '//' + code;
}
if (!this.opts.noAutoWrap) {
code = LEADER_WRAP + code + TRAILER_WRAP;
}
program = ESP.parse(code, { loc: true });
if (!this.opts.noAutoWrap) {
program = { type: SYNTAX.Program.name, body: program.body[0].expression.callee.body.body };
}
return this.instrumentASTSync(program, filename);
},
/**
* synchronous instrumentation method that instruments an AST instead.
* @method instrumentASTSync
* @param {String} program the AST to be instrumented
* @param {String} filename Optional. The name of the file from which
* the code was read. A temporary filename is generated when not specified.
* Not specifying a filename is only useful for unit tests and demonstrations
* of this library.
*/
instrumentASTSync: function (program, filename) {
filename = filename || String(new Date().getTime()) + '.js';

@@ -380,19 +404,6 @@ this.coverState = {

};
//protect from users accidentally passing in a Buffer object instead
if (typeof code !== 'string') { throw new Error('Code must be string'); }
if (code.charAt(0) === '#') { //shebang, 'comment' it out, won't affect syntax tree locations for things we care about
code = '//' + code;
}
if (!this.opts.noAutoWrap) {
code = LEADER_WRAP + code + TRAILER_WRAP;
}
program = ESP.parse(code, { loc: true });
if (!this.opts.noAutoWrap) {
program = { type: SYNTAX.Program.name, body: program.body[0].expression.callee.body.body };
}
this.walker.startWalk(program);
codegenOptions = this.opts.codeGenerationOptions || { format: { compact: !this.opts.noCompact }};
var codegenOptions = this.opts.codeGenerationOptions || { format: { compact: !this.opts.noCompact }};
//console.log(JSON.stringify(program, undefined, 2));
return this.getPreamble(code) + '\n' + ESPGEN.generate(program, codegenOptions) + '\n';
return this.getPreamble("") + '\n' + ESPGEN.generate(program, codegenOptions) + '\n';
},

@@ -521,3 +532,4 @@ /**

statementName: function (location) {
statementName: function (location, initValue) {
initValue = initValue || 0;
var sName;

@@ -527,3 +539,3 @@ this.currentState.statement += 1;

this.coverState.statementMap[sName] = location;
this.coverState.s[sName] = 0;
this.coverState.s[sName] = initValue;
return sName;

@@ -562,12 +574,16 @@ },

}
sName = this.statementName(node.loc);
incrStatementCount = astgen.statement(
astgen.postIncrement(
astgen.subscript(
astgen.dot(astgen.variable(this.currentState.trackerVar), astgen.variable('s')),
astgen.stringLiteral(sName)
if (node.type === SYNTAX.FunctionDeclaration.name) {
sName = this.statementName(node.loc, 1);
} else {
sName = this.statementName(node.loc);
incrStatementCount = astgen.statement(
astgen.postIncrement(
astgen.subscript(
astgen.dot(astgen.variable(this.currentState.trackerVar), astgen.variable('s')),
astgen.stringLiteral(sName)
)
)
)
);
this.splice(incrStatementCount, node, walker);
);
this.splice(incrStatementCount, node, walker);
}
},

@@ -574,0 +590,0 @@

{
"name": "istanbul",
"version": "0.1.37",
"version": "0.1.38",
"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",

@@ -5,0 +5,0 @@ "keywords": [ "coverage", "code coverage", "JS code coverage", "JS coverage" ],

@@ -76,4 +76,28 @@ /*jslint nomen: true */

}
},
"with a function declared in an 'unreachable' place": {
setUp: function (cb) {
code = [
'function foo(x) {',
' return bar(x);',
' function bar(y) { return y * 2 }',
'}',
'output = args[0] < 2 ? 2: foo(args[0]);'
];
verifier = helper.verifier(__filename, code);
cb();
},
"should not cover functions but should cover declarations": function (test) {
verifier.verify(test, [ 1 ], 2, { lines: { 1: 1, 2: 0, 3: 1, 5: 1 }, branches: { 1: [1, 0 ] }, functions: { 1: 0, 2: 0 }, statements: { 1: 1, 2: 0, 3: 1, 4: 0, 5: 1} });
test.done();
},
"should cover functions and declarations": function (test) {
verifier.verify(test, [ 10 ], 20, { lines: { 1: 1, 2: 1, 3: 1, 5: 1 }, branches: { 1: [ 0, 1 ]}, functions: { 1: 1, 2: 1 }, statements: { 1: 1, 2: 1, 3: 1, 4: 1, 5: 1 } });
test.done();
}
}
};
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