Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

some tests for reporting

  • Loading branch information...
commit e35d06641c796e3e935c0b33a90466fb67f05f89 1 parent 99142c0
@brianc authored
Showing with 46 additions and 2 deletions.
  1. +9 −1 lib/index.js
  2. +1 −1  test/initial-tests.js
  3. +36 −0 test/result-tests.js
View
10 lib/index.js
@@ -1,3 +1,5 @@
+var profiler = require('profiler')
+
var executeAction = function(action, callback) {
var i = 0
var doAction = function(action) {
@@ -5,10 +7,16 @@ var executeAction = function(action, callback) {
if(i++ >= action.repeat) {
return callback();
}
+ var repeat = {};
+ repeat.start = new Date()
action.run(function() {
+ repeat.end = new Date()
+ action.repeats.push(repeat)
doAction(action)
})
}
+ //set up results on action
+ action.repeats = [];
doAction(action)
}
@@ -18,7 +26,7 @@ var bench = function(config) {
var doAction = function(action) {
//no more actions to execute
if(!action) {
- return callback()
+ return callback(config)
}
action.repeat = config.repeat;
executeAction(action, function() {
View
2  test/initial-tests.js
@@ -100,7 +100,7 @@ test('async actions', function() {
calls++;
next();
})
- }, timeout+=5)
+ }, timeout+=1)
}
},{
name: 'second',
View
36 test/result-tests.js
@@ -0,0 +1,36 @@
+var helper = require(__dirname + '/test-helper')
+var bench = require(__dirname + '/../lib')
+var timeout = 10;
+var bm = bench({
+ name: 'boom',
+ repeat: 10,
+ actions:[{
+ name: 'first',
+ run: function(next) {
+ setTimeout(next, 10)
+ }
+ },{
+ name: 'second',
+ run: function(next) {
+ setTimeout(next, timeout += 10)
+ }
+ }]
+})
+
+test('results', function() {
+ bm(should.call(function(result) {
+ result.actions.length.should.equal(2)
+
+ test('first action',function() {
+ var firstAction = result.actions[0]
+ firstAction.name.should.equal('first')
+ firstAction.repeats.length.should.equal(10)
+ firstAction.repeats.forEach(function(repeat) {
+ repeat.start.should.be.instanceof(Date)
+ repeat.end.should.be.instanceof(Date)
+ })
+ })
+
+ }))
+})
+
Please sign in to comment.
Something went wrong with that request. Please try again.