Skip to content

Commit dbdc238

Browse files
fix: test
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 81f4e15 commit dbdc238

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/builtins/fetch.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { URL, fileURLToPath } from 'node:url';
2-
import { createServer } from 'node:net';
2+
import { createServer } from 'node:http';
33

44
import { strictEqual, ok } from 'node:assert';
55

@@ -16,7 +16,6 @@ export const state = async () => {
1616
export const source = (testState) => {
1717
let port = testState?.port ? ':' + testState.port : '';
1818
const url = FETCH_URL + port;
19-
console.error('[test] fetch.js visiting URL', url);
2019
return `
2120
export async function run () {
2221
const res = await fetch('${url}');
@@ -38,22 +37,22 @@ export async function test(run, testState) {
3837
throw new Error('missing port on test state');
3938
}
4039

40+
const url = FETCH_URL + (port ? ':' + port : '');
41+
4142
// Run a local server on some port
42-
console.error('[test] starting local server...');
4343
const server = createServer(async (req, res) => {
4444
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
4545
res.write(
4646
JSON.stringify({
4747
status: 'ok',
48+
url,
4849
}),
4950
);
5051
res.end();
5152
}).listen(port);
5253

5354
// Wait until the server is ready
54-
console.error('[test] waiting for server to start...');
5555
let ready = false;
56-
const url = FETCH_URL + (port ? ':' + port : '');
5756
while (!ready) {
5857
try {
5958
const res = await fetch(url);
@@ -63,8 +62,9 @@ export async function test(run, testState) {
6362
}
6463
}
6564

66-
console.error('[test] server started, running...');
6765
const { stdout, stderr } = await run();
6866
strictEqual(stderr, '');
69-
strictEqual(stdout.trim(), FETCH_URL);
67+
strictEqual(stdout.trim(), url);
68+
69+
server.close();
7070
}

0 commit comments

Comments
 (0)