Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

browser build

  • Loading branch information...
commit 5aee1dc383741af921df5e99b0d4f1c53defe5a1 1 parent 85381af
@logicalparadox logicalparadox authored
Showing with 118 additions and 100 deletions.
  1. +118 −100 chai-timers.js
View
218 chai-timers.js
@@ -1,9 +1,16 @@
-!function (name, definition) {
- if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
- else this[name] = definition();
-}('chai_timers', function () {
- // CommonJS require()
- function require(p){
+!function (context, definition) {
+ if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
+ module.exports = definition();
+ } else if (typeof define === 'function' && typeof define.amd === 'object') {
+ define(definition);
+ } else {
+ if (!context.chai) throw new Error('Chai cannot be found in current scope.');
+ context.chai.use(definition());
+ }
+}(this, function () {
+
+
+ function require(p) {
var path = require.resolve(p)
, mod = require.modules[path];
if (!mod) throw new Error('failed to require "' + p + '"');
@@ -16,7 +23,7 @@
require.modules = {};
- require.resolve = function (path){
+ require.resolve = function (path) {
var orig = path
, reg = path + '.js'
, index = path + '/index.js';
@@ -25,7 +32,7 @@
|| orig;
};
- require.register = function (path, fn){
+ require.register = function (path, fn) {
require.modules[path] = fn;
};
@@ -47,110 +54,121 @@
};
};
+ require.alias = function (from, to) {
+ var fn = require.modules[from];
+ require.modules[to] = fn;
+ };
-require.register("timers", function (module, exports, require) {
-module.exports = function (chai, _) {
+ require.register("chai-timers.js", function(module, exports, require){
+ var Timer = require('./timer');
+
+ module.exports = function (chai, _) {
+ var Assertion = chai.Assertion;
+
+ chai.Timer = Timer;
+
+ chai.timer = function (name) {
+ return new Timer(name);
+ };
+
+ Assertion.addProperty('timer', function () {
+ this.assert(
+ this._obj instanceof Timer
+ , 'expected #{this} to be a chai timer'
+ , 'expected #{this} to not be a chai timer' );
+ });
+
+ [ 'started', 'stopped', 'created' ].forEach(function (when) {
+ Assertion.overwriteProperty(when, function (_super) {
+ return function () {
+ if (this._obj instanceof Timer) {
+ _.flag(this, 'timer_when', when);
+ } else {
+ _super.call(this);
+ }
+ }
+ });
+ });
+
+ Assertion.overwriteMethod('before', function (_super) {
+ return function assertBefore (timer2, when2) {
+ var timer1 = this._obj;
+ new Assertion(timer1).to.be.a.timer;
+ new Assertion(timer2).to.be.a.timer;
+
+ var when1 = _.flag(this, 'timer_when') || 'started';
+ when2 = when2 || when1;
+ var time1 = timer1[when1].getTime()
+ , time2 = timer2[when2].getTime();
+
+ this.assert(
+ time1 < time2
+ , 'expected timer {' + timer1.name + '} to have been ' + when1 + ' before timer {' + timer2.name + '} was ' + when2
+ , 'expected timer {' + timer1.name + '} to not have been ' + when1 + ' before timer {' + timer2.name + '} was ' + when2
+ );
+ };
+ });
+
+ Assertion.overwriteMethod('after', function (_super) {
+ return function assertBefore (timer2, when2) {
+ var timer1 = this._obj;
+ new Assertion(timer1).to.be.a.timer;
+ new Assertion(timer2).to.be.a.timer;
+
+ var when1 = _.flag(this, 'timer_when') || 'started';
+ when2 = when2 || when1;
+ var time1 = timer1[when1].getTime()
+ , time2 = timer2[when2].getTime();
+
+ this.assert(
+ time1 > time2
+ , 'expected timer {' + timer1.name + '} to have been ' + when1 + ' after timer {' + timer2.name + '} was ' + when2
+ , 'expected timer {' + timer1.name + '} to not have been ' + when1 + ' after timer {' + timer2.name + '} was' + when2
+ );
+ };
+ });
- chai.Timer = function (name) {
- this.name = name || 'timer';
- this.created = new Date();
- this.marks = [];
- this.started = null;
- this.stopped = null;
- };
+ };
- chai.Timer.prototype.start = function (date) {
- this.started = date || new Date();
- return this;
- };
+ }); // module: chai-timers.js
- chai.Timer.prototype.stop = function (date) {
- this.stopped = date || new Date();
- };
+ require.register("timer.js", function(module, exports, require){
- chai.Timer.prototype.mark = function (date) {
- this.marks.push(date || new Date());
- };
+ module.exports = Timer;
- Object.defineProperty(chai.Timer.prototype, 'elapsed',
- { get: function () {
- var start = this.started.getTime()
- , stop = this.stopped.getTime();
- return stop - start;
- }
- , configurable: true
- });
+ function Timer (name) {
+ this.name = name || 'timer';
+ this.created = new Date();
+ this.marks = [];
+ this.started = null;
+ this.stopped = null;
+ };
- Object.defineProperty(chai.Timer.prototype, 'marks',
- { get: function () {
- var marks = _.flag(this, 'marks');
- return marks;
- }
- , configurable: true
- });
-
- chai.Assertion.addProperty('timer', function () {
- this.assert(
- this._obj instanceof chai.Timer
- , 'expected #{this} to be a chai timer'
- , 'expected #{this} to not be a chai timer' );
- });
-
- [ 'started', 'stopped', 'created' ].forEach(function (when) {
- chai.Assertion.overwriteProperty(when, function (_super) {
- return function () {
- if (this._obj instanceof chai.Timer) {
- _.flag(this, 'timer_when', when);
- } else {
- _super.call(this);
+ Object.defineProperty(Timer.prototype, 'elapsed',
+ { get: function () {
+ var start = this.started.getTime()
+ , stop = this.stopped.getTime();
+ return stop - start;
}
- }
});
- });
-
- chai.Assertion.overwriteMethod('before', function (_super) {
- return function assertBefore (timer2, when2) {
- var timer1 = this._obj;
- new chai.Assertion(timer1).to.be.a.timer;
- new chai.Assertion(timer2).to.be.a.timer;
-
- var when1 = _.flag(this, 'timer_when') || 'started';
- when2 = when2 || when1;
- var time1 = timer1[when1].getTime()
- , time2 = timer2[when2].getTime();
-
- this.assert(
- time1 < time2
- , 'expected timer {' + timer1.name + '} to have been ' + when1 + ' before timer {' + timer2.name + '} was ' + when2
- , 'expected timer {' + timer1.name + '} to not have been ' + when1 + ' before timer {' + timer2.name + '} was ' + when2
- );
+
+ Timer.prototype.start = function (date) {
+ this.started = date || new Date();
+ return this;
};
- });
-
- chai.Assertion.overwriteMethod('after', function (_super) {
- return function assertBefore (timer2, when2) {
- var timer1 = this._obj;
- new chai.Assertion(timer1).to.be.a.timer;
- new chai.Assertion(timer2).to.be.a.timer;
-
- var when1 = _.flag(this, 'timer_when') || 'started';
- when2 = when2 || when1;
- var time1 = timer1[when1].getTime()
- , time2 = timer2[when2].getTime();
-
- this.assert(
- time1 > time2
- , 'expected timer {' + timer1.name + '} to have been ' + when1 + ' after timer {' + timer2.name + '} was ' + when2
- , 'expected timer {' + timer1.name + '} to not have been ' + when1 + ' after timer {' + timer2.name + '} was' + when2
- );
+
+ Timer.prototype.stop = function (date) {
+ this.stopped = date || new Date();
};
- });
-};
+ Timer.prototype.mark = function (date) {
+ this.marks.push(date || new Date());
+ };
-}); // module timers
- return require('timers');
-});
+ }); // module: timer.js
-chai.use(chai_timers);
+ require.alias("./chai-timers.js", "chai-timers");
+
+ return require('chai-timers');
+});
Please sign in to comment.
Something went wrong with that request. Please try again.