diff --git a/packages/spec/express.js b/packages/spec/express.js new file mode 100644 index 000000000..dbfa0d96e --- /dev/null +++ b/packages/spec/express.js @@ -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'); + }); + }); +}); diff --git a/packages/spec/serve.js b/packages/spec/serve.js index 20c6cd191..35bbc3c8d 100644 --- a/packages/spec/serve.js +++ b/packages/spec/serve.js @@ -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 + ); + }); + }); });