diff --git a/lib/transport/node-fetch.js b/lib/transport/node-fetch.js index 459dbb1..bc95a80 100644 --- a/lib/transport/node-fetch.js +++ b/lib/transport/node-fetch.js @@ -7,6 +7,7 @@ const HttpProxyAgent = require('http-proxy-agent').HttpProxyAgent; const fetch = require('node-fetch'); const REQUIRED_PROPERTIES = [ + 'elapsedTime', 'url', 'statusCode', 'headers' @@ -35,7 +36,7 @@ class FetchTransport extends Transport { opts.timeout = req.getTimeout() || this.defaults?.timeout; opts.compress = this.defaults?.compress; - if (opts.time === undefined) opts.time = true; + if (this.defaults?.time === undefined) opts.time = true; if (req.hasQueries()) opts.searchParams = new URLSearchParams(req.getQueries()); diff --git a/test/transport/node-fetch.js b/test/transport/node-fetch.js index 9388aaf..b71f87c 100644 --- a/test/transport/node-fetch.js +++ b/test/transport/node-fetch.js @@ -246,6 +246,26 @@ describe('Request HTTP transport', () => { .catch(assert.ifError); }); + it('allows disabling of timing request', () => { + nock.cleanAll(); + api.get('/').reply(200, responseBody); + + const ctx = createContext(url); + const options = { + defaults: { + time: false + } + }; + + return new FetchTransport(options) + .execute(ctx) + .then((ctx) => { + const timeTaken = ctx.res.elapsedTime; + assert.isUndefined(timeTaken); + }) + .catch(assert.ifError); + }); + describe('JSON parsing', () => { it('if json default option is passed in as true, parse body as json', () => { nock.cleanAll();