Skip to content

Commit b2c5f54

Browse files
bkwgr2m
authored andcommitted
test supplying a lookup function through an agent
1 parent 2b7e1ab commit b2c5f54

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const fs = require('fs');
1717
const path = require('path');
1818
const stream = require('stream');
1919
const { parse: parseURL, URLSearchParams } = require('url');
20+
const { lookup } = require('dns');
2021

2122
let convert;
2223
try { convert = require('encoding').convert; } catch(e) { }
@@ -1531,6 +1532,19 @@ describe('node-fetch', () => {
15311532
.and.have.property('message').that.includes('Could not create Buffer')
15321533
.and.that.includes('embedded error');
15331534
});
1535+
1536+
it("supports supplying a lookup function to the agent", function() {
1537+
const url = `${base}redirect/301`;
1538+
let called = 0;
1539+
function lookupSpy(hostname, options, callback) {
1540+
called++;
1541+
return lookup(hostname, options, callback);
1542+
}
1543+
const agent = http.Agent({ lookup: lookupSpy });
1544+
return fetch(url, { agent }).then(() => {
1545+
expect(called).to.equal(2);
1546+
});
1547+
});
15341548
});
15351549

15361550
describe('Headers', function () {

0 commit comments

Comments
 (0)