Skip to content

Commit

Permalink
test: add tests for server timings
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-drexler authored and dmbch committed Mar 12, 2018
1 parent a4d7dec commit ebc0c37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/spec/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env node, mocha */

var assert = require('assert');

function clearRequireCache() {
Object.keys(require.cache).forEach(function(key) {
delete require.cache[key];
});
}

describe('express', function() {
beforeEach(clearRequireCache);
describe('timings', function() {
it('uses server-timings middleware when enableServerTimings is true', function() {
var hopsConfig = require('hops-config');
hopsConfig.enableServerTimings = true;
var hopsExpressTimings = require('hops-express').utils.timings;
var res = { locals: {} };
var req = {};

hopsExpressTimings(req, res, function() {});
assert(typeof res.locals.timings.start('foo') !== 'undefined');
});

it('uses noop timings middleware when enableServerTimings is false', function() {
var hopsConfig = require('hops-config');
hopsConfig.enableServerTimings = false;
var hopsExpressTimings = require('hops-express').utils.timings;
var res = { locals: {} };
var req = {};

hopsExpressTimings(req, res, function() {});
assert(typeof res.locals.timings.start('foo') === 'undefined');
});
});
});
8 changes: 8 additions & 0 deletions packages/spec/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,12 @@ describe('production server', function() {
assert(response.status === 404);
});
});

it('adds server-timing header', function() {
return fetch('http://localhost:8080/').then(function(response) {
assert(
response.headers.get('server-timing').indexOf('desc="Request"') > -1
);
});
});
});

0 comments on commit ebc0c37

Please sign in to comment.