Skip to content

Commit

Permalink
chore: make sure elapsedTime is on response and unit tested
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierbower committed Oct 9, 2023
1 parent 26415a8 commit dc3ea44
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/transport/node-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const HttpProxyAgent = require('http-proxy-agent').HttpProxyAgent;
const fetch = require('node-fetch');

const REQUIRED_PROPERTIES = [
'elapsedTime',
'url',
'statusCode',
'headers'
Expand Down Expand Up @@ -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());

Expand Down
20 changes: 20 additions & 0 deletions test/transport/node-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit dc3ea44

Please sign in to comment.