Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

include the top source in the readme

  • Loading branch information...
commit ab261e13cb0d064be175ade9c2e7c792f98e283c 1 parent 34f391b
@substack authored
Showing with 63 additions and 0 deletions.
  1. +62 −0 README.markdown
  2. +1 −0  example/top/src.js
View
62 README.markdown
@@ -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
1  example/top/src.js
@@ -14,4 +14,5 @@ var iv = setInterval(function () {
clearInterval(iv);
end();
}
+ else boop()
}, 100);
Please sign in to comment.
Something went wrong with that request. Please try again.