Permalink
Browse files

tiny example in the readme in favor of the bigger one

  • Loading branch information...
1 parent 2627d6a commit 6c2e0e21d777f9f372387a257e7c77405878ae03 @substack committed Jul 18, 2011
Showing with 30 additions and 60 deletions.
  1. +12 −60 README.markdown
  2. +18 −0 example/tiny.js
View
@@ -9,84 +9,36 @@ Bunker is a module to calculate code coverage using native javascript
examples
========
-top
----
-
-example/top/run.js:
+tiny
+----
````javascript
-
var bunker = require('bunker');
-var fs = require('fs');
-var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
+var b = bunker('var x = 0; for (var i = 0; i < 30; i++) { x++ }');
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:
+b.run();
-````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);
+Object.keys(counts).forEach(function (key) {
+ var count = counts[key];
+ console.log(count.times + ' : ' + count.node.source());
+});
````
output:
- $ node example/top/run.js
- 279 : i<30
- 270 : nop()
- 270 : nop();
- 270 : i++
- 18 : boop();
- 10 : ++times
- 10 : ++times===10
- 1 : setInterval(function(){if(++times===10){clearInterval(iv);end()}else boop()},100)
- 1 : clearInterval(iv);
- 1 : clearInterval(iv)
- 1 : end();
- 1 : end()
+ $ node example/tiny.js
+ 31 : i<30
+ 60 : x++;
+ 30 : i++
methods
=======
View
@@ -0,0 +1,18 @@
+var bunker = require('bunker');
+var b = bunker('var x = 0; for (var i = 0; i < 30; i++) { x++ }');
+
+var counts = {};
+
+b.on('node', function (node) {
+ if (!counts[node.range]) {
+ counts[node.range] = { times : 0, node : node };
+ }
+ counts[node.range].times ++;
+});
+
+b.run();
+
+Object.keys(counts).forEach(function (key) {
+ var count = counts[key];
+ console.log(count.times + ' : ' + count.node.source());
+});

0 comments on commit 6c2e0e2

Please sign in to comment.