Skip to content

Commit 832638a

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

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
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
}

test/test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,25 @@ const builtinsCases = await readdir(new URL('./builtins', import.meta.url));
2525
suite('Builtins', () => {
2626
for (const filename of builtinsCases) {
2727
const name = filename.slice(0, -3);
28+
if (!name.includes("fetch")) { continue; }
2829
test(name, async () => {
30+
const testModule = await import(`./builtins/${filename}`);
2931
const {
3032
state,
31-
source,
3233
test: runTest,
3334
disableFeatures,
3435
enableFeatures,
35-
} = await import(`./builtins/${filename}`);
36+
} = testModule;
3637

3738
// If an args object was provided, generate the arguments to feed to both
3839
// source generation (if necessary) and the test run itself
3940
let stateFn = state ?? noOp;
4041
const stateObj = await stateFn();
4142

4243
// If the source is a function then invoke it to generate the source string, possibly with arguments
44+
let source = testModule.source;
4345
if (typeof source === 'function') {
44-
source(stateObj);
46+
source = source(stateObj);
4547
}
4648

4749
const { component } = await componentize(

0 commit comments

Comments
 (0)