Skip to content

Commit caf5335

Browse files
authored
add more tests related to node:http (#4448)
1 parent 69aedfe commit caf5335

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

src/workerd/api/node/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,19 @@ wd_test(
432432
],
433433
)
434434

435+
js_binary(
436+
name = "http-agent-server",
437+
entry_point = "tests/http-agent-server.js",
438+
)
439+
435440
wd_test(
436441
src = "tests/http-agent-nodejs-test.wd-test",
437442
args = ["--experimental"],
438443
data = ["tests/http-agent-nodejs-test.js"],
444+
sidecar = "http-agent-server",
445+
sidecar_port_bindings = [
446+
"PONG_SERVER_PORT",
447+
],
439448
)
440449

441450
wd_test(

src/workerd/api/node/tests/http-agent-nodejs-test.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
// https://opensource.org/licenses/Apache-2.0
44

55
import http from 'node:http';
6-
import { strictEqual } from 'node:assert';
6+
import { strictEqual, ok } from 'node:assert';
7+
8+
export const checkPortsSetCorrectly = {
9+
test(_ctrl, env) {
10+
const keys = ['PONG_SERVER_PORT'];
11+
for (const key of keys) {
12+
strictEqual(typeof env[key], 'string');
13+
ok(env[key].length > 0);
14+
}
15+
},
16+
};
717

818
// Test is taken from test/parallel/test-http-agent-getname.js
919
export const testHttpAgentGetName = {
@@ -50,3 +60,18 @@ export const testHttpAgentGetName = {
5060
strictEqual(agent.getName({ family }), `localhost:::${family}`);
5161
},
5262
};
63+
64+
// Test is taken from test/parallel/test-http-agent-null.js
65+
export const testHttpAgentNull = {
66+
async test(_ctrl, env) {
67+
const { promise, resolve } = Promise.withResolvers();
68+
http.get(
69+
{
70+
agent: null,
71+
port: env.PONG_SERVER_PORT,
72+
},
73+
resolve
74+
);
75+
await promise;
76+
},
77+
};

src/workerd/api/node/tests/http-agent-nodejs-test.wd-test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const unitTests :Workerd.Config = (
99
],
1010
compatibilityDate = "2025-01-15",
1111
compatibilityFlags = ["nodejs_compat", "experimental"],
12+
bindings = [
13+
(name = "PONG_SERVER_PORT", fromEnvironment = "PONG_SERVER_PORT"),
14+
],
1215
)
1316
),
1417
( name = "internet", network = ( allow = ["private"] ) ),
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017-2022 Cloudflare, Inc.
2+
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
3+
// https://opensource.org/licenses/Apache-2.0
4+
5+
// This is a sidecar that runs alongside the http-client-nodejs-test.* tests.
6+
// It is executed using the appropriate Node.js version defined in WORKSPACE.
7+
const http = require('node:http');
8+
9+
function reportPort(server) {
10+
console.info(`Listening on port ${server.address().port}`);
11+
}
12+
13+
const pongServer = http.createServer((req, res) => {
14+
req.resume();
15+
req.on('end', () => {
16+
res.writeHead(200);
17+
res.end('pong');
18+
});
19+
});
20+
pongServer.listen(process.env.PONG_SERVER_PORT, () => reportPort(pongServer));

src/workerd/api/node/tests/http-client-nodejs-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import http from 'node:http';
66
import https from 'node:https';
77
import { strictEqual, ok, deepStrictEqual, throws } from 'node:assert';
8-
import { mock } from 'node:test';
98

109
export const checkPortsSetCorrectly = {
1110
test(_ctrl, env) {

0 commit comments

Comments
 (0)