chocolate
Version:
A full stack Node.js web framework built using Coffeescript
120 lines (116 loc) • 4.91 kB
JavaScript
// Generated by CoffeeScript 1.12.6
(function() {
var Debugate;
Debugate = require('../general/debugate');
describe('Debugate', function() {
return describe('profile', function() {
var f1;
it('should count iterations', function() {
var i;
for (i = 1; i <= 5; i++) {
Debugate.profile.count('Test count');
}
return expect(Debugate.profile.spent('Test count').count).toBe(5);
});
f1 = function(cb) {
return setTimeout((function() {
return cb(new Date().getTime());
}), 250);
};
it('should calculate time spent (250 ms) with start and end', function() {
var time1;
Debugate.profile.start('Test time spent');
time1 = null;
runs(function() {
return f1(function(time) {
time1 = time;
return Debugate.profile.end('Test time spent');
});
});
waitsFor((function() {
return time1 != null;
}), 'call of f1()', 1000);
return runs(function() {
expect(Debugate.profile.spent('Test time spent').time).toBeGreaterThan((250 - 5) * 1000);
return expect(Debugate.profile.spent('Test time spent').time).toBeLessThan((250 + 5) * 1000);
});
});
it('should calculate time spent (add 250 ms so total is 500 ms) with toggle', function() {
var time1;
Debugate.profile.toggle('Test time spent');
time1 = null;
runs(function() {
return f1(function(time) {
time1 = time;
return Debugate.profile.toggle('Test time spent');
});
});
waitsFor((function() {
return time1 != null;
}), 'call of f1()', 1000);
return runs(function() {
expect(Debugate.profile.spent('Test time spent').time).toBeGreaterThan((500 - 10) * 1000);
return expect(Debugate.profile.spent('Test time spent').time).toBeLessThan((500 + 10) * 1000);
});
});
it('should reset counter', function() {
Debugate.profile.reset('Test time spent');
return expect(Debugate.profile.spent('Test time spent').time).toBe(0);
});
it('should calculate time spent with iterative pulse', function() {
var time1, time2, time3;
Debugate.profile.reset();
Debugate.profile.pulse('Test time spent');
time1 = time2 = time3 = null;
runs(function() {
return f1(function(time) {
time1 = time;
Debugate.profile.pulse('Test time spent');
return f1(function(time) {
time2 = time;
Debugate.profile.pulse('Test time spent');
return f1(function(time) {
time3 = time;
return Debugate.profile.pulse('Test time spent', false);
});
});
});
});
waitsFor((function() {
return (time1 != null) && (time2 != null) && (time3 != null);
}), 'three calls of f1()', 1000);
return runs(function() {
expect(Debugate.profile.spent('Test time spent' + '0').time).toBeGreaterThan((250 - 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '0').time).toBeLessThan((250 + 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '1').time).toBeGreaterThan((250 - 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '1').time).toBeLessThan((250 + 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '2').time).toBeGreaterThan((250 - 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '2').time).toBeLessThan((250 + 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '0').count).toBe(1);
expect(Debugate.profile.spent('Test time spent').total.count).toBe(3);
return expect(Debugate.profile.spent('Test time spent').total.time).toBeGreaterThan((750 - 5) * 1000);
});
});
return it('should calculate time spent with pulse like toggle', function() {
var time1, time2;
Debugate.profile.reset();
Debugate.profile.pulse('Test time spent', true);
time1 = time2 = null;
runs(function() {
return f1(function(time) {
time1 = time;
return Debugate.profile.pulse('Test time spent', false);
});
});
waitsFor((function() {
return time1 != null;
}), 'two calls of f1()', 1000);
return runs(function() {
expect(Debugate.profile.spent('Test time spent' + '0').time).toBeGreaterThan((250 - 5) * 1000);
expect(Debugate.profile.spent('Test time spent' + '0').time).toBeLessThan((250 + 5) * 1000);
return expect(Debugate.profile.spent('Test time spent' + '1').time).toBe(0);
});
});
});
});
}).call(this);