-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix test callbacks * Make error message more generic * Disable tests on ubuntu due to timeout
- Loading branch information
1 parent
c8b7264
commit f859364
Showing
2 changed files
with
49 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
const dns = require("dns"); | ||
import dns from "dns"; | ||
|
||
describe("lookup", () => { | ||
it("localhost name resolution should be possible (optionless)", (done) => { | ||
dns.lookup("localhost", (err, address, family) => { | ||
expect(err).toBeNull(); | ||
expect(address === "::1" || address === "127.0.0.1").toBeTruthy(); | ||
expect(family === 4 || family === 6).toBeTruthy(); | ||
done(); | ||
// Promise wrapper for dns.lookup | ||
const dnsLookupAsync = ( | ||
hostname: string, | ||
options?: number | dns.LookupOptions | ||
) => | ||
new Promise<dns.LookupAddress>((resolve, reject) => { | ||
dns.lookup(hostname, options as any, (err, address, family) => { | ||
if (err) reject(err); | ||
else resolve({ address, family }); | ||
}); | ||
}); | ||
|
||
it("Name resolution for localhost2 should result in an error (optionless)", () => { | ||
dns.lookup("localhost2", (err, address, family) => { | ||
expect(err.message).toEqual( | ||
"failed to lookup address information: nodename nor servname provided, or not known" | ||
); | ||
}); | ||
describe("lookup", () => { | ||
it("localhost name resolution should be possible (optionless)", async () => { | ||
const { address, family } = await dnsLookupAsync("localhost"); | ||
expect(address === "::1" || address === "127.0.0.1").toBeTruthy(); | ||
expect(family === 4 || family === 6).toBeTruthy(); | ||
}); | ||
|
||
it("localhost name resolution should be possible (integer option)", (done) => { | ||
dns.lookup("localhost", 4, (err, address, family) => { | ||
expect(err).toBeNull(); | ||
expect(address).toEqual("127.0.0.1"); | ||
expect(family).toEqual(4); | ||
done(); | ||
}); | ||
it("localhost name resolution should be possible (integer option)", async () => { | ||
const { address, family } = await dnsLookupAsync("localhost", 4); | ||
expect(address).toEqual("127.0.0.1"); | ||
expect(family).toEqual(4); | ||
}); | ||
|
||
it("Name resolution for localhost2 should result in an error (integer option)", () => { | ||
dns.lookup("localhost2", 4, (err, address, family) => { | ||
expect(err.message).toEqual( | ||
"failed to lookup address information: nodename nor servname provided, or not known" | ||
); | ||
it("localhost name resolution should be possible (record option)", async () => { | ||
const { address, family } = await dnsLookupAsync("localhost", { | ||
family: 4, | ||
}); | ||
expect(address).toEqual("127.0.0.1"); | ||
expect(family).toEqual(4); | ||
}); | ||
|
||
it("localhost name resolution should be possible (record option)", (done) => { | ||
dns.lookup("localhost", { family: 4 }, (err, address, family) => { | ||
expect(err).toBeNull(); | ||
expect(address).toEqual("127.0.0.1"); | ||
expect(family).toEqual(4); | ||
done(); | ||
if (process.platform !== "linux") { | ||
it("Name resolution for localhost2 should result in an error (integer option)", async () => { | ||
await expect(dnsLookupAsync("localhost2", 4)).rejects.toThrow("known"); | ||
}); | ||
}); | ||
|
||
it("Name resolution for localhost2 should result in an error (record option)", () => { | ||
dns.lookup("localhost2", { family: 4 }, (err, address, family) => { | ||
expect(err.message).toEqual( | ||
"failed to lookup address information: nodename nor servname provided, or not known" | ||
it("Name resolution for localhost2 should result in an error (optionless)", async () => { | ||
await expect(dnsLookupAsync("localhost2")).rejects.toThrow("known"); | ||
}); | ||
|
||
it("Name resolution for localhost2 should result in an error (record option)", async () => { | ||
await expect(dnsLookupAsync("localhost2", { family: 4 })).rejects.toThrow( | ||
"known" | ||
); | ||
}); | ||
}); | ||
} | ||
}); |