Permalink
Browse files

include the top source in the readme

  • Loading branch information...
1 parent 34f391b commit ab261e13cb0d064be175ade9c2e7c792f98e283c @substack committed Jul 18, 2011
Showing with 63 additions and 0 deletions.
  1. +62 −0 README.markdown
  2. +1 −0 example/top/src.js
View
@@ -9,6 +9,68 @@ Bunker is a module to calculate code coverage using native javascript
examples
========
+top
+---
+
+example/top/run.js:
+
+````javascript
+
+var bunker = require('../../');
+var fs = require('fs');
+var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
+
+var counts = {};
+
+var b = bunker(src);
+b.on('node', function (node) {
+ if (!counts[node.range]) {
+ counts[node.range] = { times : 0, node : node };
+ }
+ counts[node.range].times ++;
+});
+
+b.run({
+ setInterval : setInterval,
+ clearInterval : clearInterval,
+ end : function () {
+ Object.keys(counts)
+ .sort(function (a, b) {
+ return counts[b].times - counts[a].times
+ })
+ .forEach(function (key) {
+ var count = counts[key];
+ console.log(count.times + ' ' + count.node.source());
+ })
+ ;
+ }
+});
+````
+
+example/top/src.js:
+
+````javascript
+function boop () {
+ for (var i = 0; i < 30; i++) {
+ nop();
+ }
+}
+
+function nop () {
+ return undefined;
+}
+
+var times = 0;
+var iv = setInterval(function () {
+ if (++times === 10) {
+ clearInterval(iv);
+ end();
+ }
+ else boop()
+}, 100);
+````
+
+output:
methods
View
@@ -14,4 +14,5 @@ var iv = setInterval(function () {
clearInterval(iv);
end();
}
+ else boop()
}, 100);

0 comments on commit ab261e1

Please sign in to comment.