-
Notifications
You must be signed in to change notification settings - Fork 5k
node:test: support the (t, done) callback signature in tests and hooks #28502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
65c98c3
node:test: support the (t, done) callback signature in tests and hooks
robobun 6d493e4
[autofix.ci] apply automated fixes
autofix-ci[bot] 9d60cc2
test: quarantine test-set-http-max-http-headers.js (unmasked by the d…
robobun 06459ca
test: skip the never-called-done timeout case on Windows
robobun 0961644
test: quarantine test-net-connect-memleak.js on musl x64 (FR timing)
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { expect, it } from "bun:test"; | ||
| import { connect } from "node:net"; | ||
|
|
||
| it("emits ERR_INVALID_IP_ADDRESS when a custom lookup yields a non-string address", async () => { | ||
| // Node validates `typeof ip === "string"` before isIP(); an array like | ||
| // ["127.0.0.1"] stringifies into a valid IP, so it must not connect. | ||
| for (const family of [4, 6] as const) { | ||
| const { promise, resolve, reject } = Promise.withResolvers<Error & { code?: string }>(); | ||
| const socket = connect({ | ||
| host: "example.com", | ||
| port: 80, | ||
| family, | ||
| lookup: (_host, _options, callback) => { | ||
| callback(null, ["127.0.0.1"] as unknown as string, family); | ||
| }, | ||
| }); | ||
| socket.on("connect", () => reject(new Error("connected with an invalid lookup result"))); | ||
| socket.on("error", resolve); | ||
| try { | ||
| const error = await promise; | ||
| expect(error.code).toBe("ERR_INVALID_IP_ADDRESS"); | ||
| } finally { | ||
| socket.destroy(); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it("passes a string address from a custom lookup through to the connection", async () => { | ||
| // A loopback server observes the connection even though the hostname never | ||
| // resolves, proving the lookup result is what gets connected to. | ||
| using server = Bun.listen({ | ||
| hostname: "127.0.0.1", | ||
| port: 0, | ||
| socket: { | ||
| data() {}, | ||
| }, | ||
| }); | ||
| const { promise, resolve, reject } = Promise.withResolvers<void>(); | ||
| const socket = connect({ | ||
| host: "definitely-not-resolvable.example.invalid", | ||
| port: server.port, | ||
| family: 4, | ||
| lookup: (_host, _options, callback) => { | ||
| callback(null, "127.0.0.1", 4); | ||
| }, | ||
| }); | ||
| socket.on("connect", () => resolve()); | ||
| socket.on("error", reject); | ||
| try { | ||
| await promise; | ||
| } finally { | ||
| socket.destroy(); | ||
| } | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.