Enable code coverage

Former-commit-id: 9b52247b6e880f15895842e4ff34c15fc99fd1eb
This commit is contained in:
Mathias Bynens
2013-05-29 17:51:57 +02:00
parent 9dd8f62c8a
commit d1fb379a40
10 changed files with 17970 additions and 20 deletions

3
.gitignore vendored
View File

@@ -6,3 +6,6 @@
node_modules
vendor/closure-compiler
vendor/uglifyjs
coverage/index.html
coverage/*.json
coverage/lodash/vendor

View File

@@ -6,8 +6,9 @@
*.md
bower.json
component.json
coverage
doc
node_modules
Gruntfile.js
perf
test
vendor/*.gz

63
Gruntfile.js Normal file
View File

@@ -0,0 +1,63 @@
module.exports = function(grunt) {
grunt.initConfig({
'shell': {
'options': {
'stdout': true,
'stderr': true,
'failOnError': true,
'execOptions': {
'cwd': 'test'
}
},
'cover': {
'command': 'istanbul cover --report "html" --verbose --dir "coverage" "test.js"'
},
'test-rhino': {
'command': 'echo "Testing in Rhino..."; rhino -opt -1 "test.js" "../dist/lodash.compat.js"; rhino -opt -1 "test.js" "../dist/lodash.compat.min.js"'
},
'test-rhino-require': {
'command': 'echo "Testing in Rhino with -require..."; rhino -opt -1 -require "test.js" "../dist/lodash.compat.js"; rhino -opt -1 -require "test.js" "../dist/lodash.compat.min.js";'
},
'test-ringo': {
'command': 'echo "Testing in Ringo..."; ringo -o -1 "test.js" "../dist/lodash.compat.js"; ringo -o -1 "test.js" "../dist/lodash.compat.min.js"'
},
'test-phantomjs': {
'command': 'echo "Testing in PhantomJS..."; phantomjs "test.js" "../dist/lodash.compat.js"; phantomjs "test.js" "../dist/lodash.compat.min.js"'
},
'test-narwhal': {
'command': 'echo "Testing in Narwhal..."; export NARWHAL_OPTIMIZATION=-1; narwhal "test.js" "../dist/lodash.compat.js"; narwhal "test.js" "../dist/lodash.compat.min.js"'
},
'test-node': {
'command': 'echo "Testing in Node..."; node "test.js" "../dist/lodash.compat.js"; node "test.js" "../dist/lodash.compat.min.js"'
},
'test-node-build': {
'command': 'echo "Testing build..."; node "test-build.js"'
},
'test-browser': {
'command': 'echo "Testing in a browser..."; open "index.html"'
}
}
});
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('cover', 'shell:cover');
grunt.registerTask('test', [
'shell:test-rhino',
//'shell:test-rhino-require',
'shell:test-ringo',
'shell:test-phantomjs',
'shell:test-narwhal',
'shell:test-node',
'shell:test-node-build',
'shell:test-browser'
]);
grunt.registerTask('default', [
'shell:test-node',
'shell:test-node-build',
'cover'
]);
};

View File

@@ -246,6 +246,15 @@ require({
});
```
## Unit tests & code coverage
After cloning this repository, run `npm install` to install the dependencies needed for Lo-Dash development and testing. You may want to install Istanbul _globally_ using `npm install istanbul -g`.
Once thats done, you can run the unit tests in Node using `npm test` or `node test/test.js`. To run the tests in Rhino, Ringo, Narwhal, PhantomJS, and web browsers as well, use `grunt test`.
To generate [the code coverage report](http://rawgithub.com/bestiejs/lodash/master/coverage/lodash/lodash.js.html), use `grunt cover`.
## Release Notes
### <sup>v1.2.1</sup>

333
coverage/lodash/index.html Normal file
View File

@@ -0,0 +1,333 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for lodash/</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../prettify.css">
<style>
body, html {
margin:0; padding: 0;
}
body {
font-family: Helvetica Neue, Helvetica,Arial;
font-size: 10pt;
}
div.header, div.footer {
background: #eee;
padding: 1em;
}
div.header {
z-index: 100;
position: fixed;
top: 0;
border-bottom: 1px solid #666;
width: 100%;
}
div.footer {
border-top: 1px solid #666;
}
div.body {
margin-top: 10em;
}
div.meta {
font-size: 90%;
text-align: center;
}
h1, h2, h3 {
font-weight: normal;
}
h1 {
font-size: 12pt;
}
h2 {
font-size: 10pt;
}
pre {
font-family: Consolas, Menlo, Monaco, monospace;
margin: 0;
padding: 0;
line-height: 14px;
font-size: 14px;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
div.path { font-size: 110%; }
div.path a:link, div.path a:visited { color: #000; }
table.coverage { border-collapse: collapse; margin:0; padding: 0 }
table.coverage td {
margin: 0;
padding: 0;
color: #111;
vertical-align: top;
}
table.coverage td.line-count {
width: 50px;
text-align: right;
padding-right: 5px;
}
table.coverage td.line-coverage {
color: #777 !important;
text-align: right;
border-left: 1px solid #666;
border-right: 1px solid #666;
}
table.coverage td.text {
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 40px;
}
table.coverage td span.cline-neutral {
background: #eee;
}
table.coverage td span.cline-yes {
background: #b5d592;
color: #999;
}
table.coverage td span.cline-no {
background: #fc8c84;
}
.cstat-yes { color: #111; }
.cstat-no { background: #fc8c84; color: #111; }
.fstat-no { background: #ffc520; color: #111 !important; }
.cbranch-no { background: yellow !important; color: #111; }
.missing-if-branch {
display: inline-block;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: black;
color: yellow;
xtext-decoration: line-through;
}
.missing-if-branch .typ {
color: inherit !important;
}
.entity, .metric { font-weight: bold; }
.metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; }
.metric small { font-size: 80%; font-weight: normal; color: #666; }
div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; }
div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; }
div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; }
div.coverage-summary th.file { border-right: none !important; }
div.coverage-summary th.pic { border-left: none !important; text-align: right; }
div.coverage-summary th.pct { border-right: none !important; }
div.coverage-summary th.abs { border-left: none !important; text-align: right; }
div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; }
div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; }
div.coverage-summary td.file { text-align: right; border-left: 1px solid #666; white-space: nowrap; }
div.coverage-summary td.pic { min-width: 120px !important; }
div.coverage-summary a:link { text-decoration: none; color: #000; }
div.coverage-summary a:visited { text-decoration: none; color: #333; }
div.coverage-summary a:hover { text-decoration: underline; }
div.coverage-summary tfoot td { border-top: 1px solid #666; }
div.coverage-summary .yui3-datatable-sort-indicator, div.coverage-summary .dummy-sort-indicator {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
}
div.coverage-summary .yui3-datatable-sort-indicator {
background: url("http://yui.yahooapis.com/3.6.0/build/datatable-sort/assets/skins/sam/sort-arrow-sprite.png") no-repeat scroll 0 0 transparent;
}
div.coverage-summary .yui3-datatable-sorted .yui3-datatable-sort-indicator {
background-position: 0 -20px;
}
div.coverage-summary .yui3-datatable-sorted-desc .yui3-datatable-sort-indicator {
background-position: 0 -10px;
}
.high { background: #b5d592 !important; }
.medium { background: #ffe87c !important; }
.low { background: #fc8c84 !important; }
span.cover-fill, span.cover-empty {
display:inline-block;
border:1px solid #444;
background: white;
height: 12px;
}
span.cover-fill {
background: #ccc;
border-right: 1px solid #444;
}
span.cover-empty {
background: white;
border-left: none;
}
span.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">lodash/</span></h1>
<h2>
Statements: <span class="metric">93.59% <small>(1153 / 1232)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Branches: <span class="metric">87.09% <small>(789 / 906)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Functions: <span class="metric">87.5% <small>(168 / 192)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
Lines: <span class="metric">93.64% <small>(1149 / 1227)</small></span> &nbsp;&nbsp;&nbsp;&nbsp;
</h2>
<div class="path"><a href="../index.html">All files</a> &#187; lodash/</div>
</div>
<div class="body">
<div class="coverage-summary">
<table>
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="lodash.js"><a href="lodash.js.html">lodash.js</a></td>
<td data-value="93.59" class="pic high"><span class="cover-fill" style="width: 93px;"></span><span class="cover-empty" style="width:7px;"></span></td>
<td data-value="93.59" class="pct high">93.59%</td>
<td data-value="1232" class="abs high">(1153&nbsp;/&nbsp;1232)</td>
<td data-value="87.09" class="pct high">87.09%</td>
<td data-value="906" class="abs high">(789&nbsp;/&nbsp;906)</td>
<td data-value="87.5" class="pct high">87.5%</td>
<td data-value="192" class="abs high">(168&nbsp;/&nbsp;192)</td>
<td data-value="93.64" class="pct high">93.64%</td>
<td data-value="1227" class="abs high">(1149&nbsp;/&nbsp;1227)</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Wed May 29 2013 17:33:01 GMT+0200 (CEST)</div>
</div>
<script src="../prettify.js"></script>
<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script>
YUI().use('datatable', function (Y) {
var formatters = {
pct: function (o) {
o.className += o.record.get('classes')[o.column.key];
try {
return o.value.toFixed(2) + '%';
} catch (ex) { return o.value + '%'; }
},
html: function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.record.get(o.column.key + '_html');
}
},
defaultFormatter = function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.value;
};
function getColumns(theadNode) {
var colNodes = theadNode.all('tr th'),
cols = [],
col;
colNodes.each(function (colNode) {
col = {
key: colNode.getAttribute('data-col'),
label: colNode.get('innerHTML') || ' ',
sortable: !colNode.getAttribute('data-nosort'),
className: colNode.getAttribute('class'),
type: colNode.getAttribute('data-type'),
allowHTML: colNode.getAttribute('data-html') === 'true' || colNode.getAttribute('data-fmt') === 'html'
};
col.formatter = formatters[colNode.getAttribute('data-fmt')] || defaultFormatter;
cols.push(col);
});
return cols;
}
function getRowData(trNode, cols) {
var tdNodes = trNode.all('td'),
i,
row = { classes: {} },
node,
name;
for (i = 0; i < cols.length; i += 1) {
name = cols[i].key;
node = tdNodes.item(i);
row[name] = node.getAttribute('data-value') || node.get('innerHTML');
row[name + '_html'] = node.get('innerHTML');
row.classes[name] = node.getAttribute('class');
//Y.log('Name: ' + name + '; Value: ' + row[name]);
if (cols[i].type === 'number') { row[name] = row[name] * 1; }
}
//Y.log(row);
return row;
}
function getData(tbodyNode, cols) {
var data = [];
tbodyNode.all('tr').each(function (trNode) {
data.push(getRowData(trNode, cols));
});
return data;
}
function replaceTable(node) {
if (!node) { return; }
var cols = getColumns(node.one('thead')),
data = getData(node.one('tbody'), cols),
table,
parent = node.get('parentNode');
table = new Y.DataTable({
columns: cols,
data: data,
sortBy: 'file'
});
parent.set('innerHTML', '');
table.render(parent);
}
Y.on('domready', function () {
replaceTable(Y.one('div.coverage-summary table'));
if (typeof prettyPrint === 'function') {
prettyPrint();
}
});
});
</script>
</body>
</html>

17552
coverage/lodash/lodash.js.html Normal file

File diff suppressed because it is too large Load Diff

1
coverage/prettify.css Normal file
View File

@@ -0,0 +1 @@
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}

1
coverage/prettify.js Normal file

File diff suppressed because one or more lines are too long

View File

@@ -2,7 +2,7 @@
"name": "lodash",
"version": "1.2.1",
"description": "A low-level utility library delivering consistency, customization, performance, and extra features.",
"homepage": "http://lodash.com",
"homepage": "http://lodash.com/",
"license": "MIT",
"main": "./dist/lodash.js",
"keywords": [
@@ -29,6 +29,11 @@
"bin": {
"lodash": "./build.js"
},
"devDependencies": {
"istanbul": "~0.1.35",
"grunt": "~0.4.1",
"grunt-shell": "~0.2.2"
},
"engines": [
"node",
"rhino"

View File

@@ -1,18 +0,0 @@
cd "$(dirname "$0")"
for cmd in rhino "rhino -require" narwhal ringo phantomjs; do
echo "Testing in $cmd..."
$cmd test.js ../dist/lodash.compat.js && $cmd test.js ../dist/lodash.compat.min.js
echo ""
done
echo "Testing in node..."
node test.js ../dist/lodash.js && node test.js ../dist/lodash.min.js
echo ""
echo "Testing build..."
node test-build.js
echo ""
echo "Testing in a browser..."
open index.html