-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
43 lines (31 loc) · 1.16 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const chai = require("chai"), assert = chai.assert;
describe("express-chrono", () => {
it("should require", () => {
const chrono = require("./index");
});
it("should have middleware", () => {
const chrono = require("./index");
assert.isFunction(chrono);
const chronoExpress = chrono();
assert.property(chronoExpress, "middleware");
assert.isObject(chronoExpress.middleware);
assert.property(chronoExpress.middleware, "start");
assert.property(chronoExpress.middleware, "stop");
assert.property(chronoExpress, "Chronometer");
});
it("can measure time", (done) => {
const chrono = require("./index")();
let req = {};
chrono.middleware.start(req, {}, () => {
assert.property(req, "chrono");
});
setTimeout(() => {
chrono.middleware.stop(req, {}, () => {
assert.property(req, "chrono");
// this will be approximately 10ms +/- a few microseconds
assert.equal(Math.floor(req.chrono.valueOf() * 100)*10, 10);
done();
});
}, 10);
});
});