Skip to content

Commit 18d7fed

Browse files
test: add test case for fetch-event integration
1 parent 16b39ad commit 18d7fed

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
addEventListener("fetch", (event) =>
2+
event.respondWith(
3+
(async () => {
4+
return new Response("Hello World");
5+
})(),
6+
),
7+
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { strictEqual } from 'node:assert';
2+
3+
import { HTTPServer } from '@bytecodealliance/preview2-shim/http';
4+
5+
import { getRandomPort } from '../../util.js';
6+
7+
export const enableFeatures = ['http', 'fetch-event'];
8+
export const worldName = 'test3';
9+
10+
export async function test(instance) {
11+
const server = new HTTPServer(instance.incomingHandler);
12+
let port = await getRandomPort();
13+
server.listen(port);
14+
15+
try {
16+
const resp = await fetch(`http://localhost:${port}`);
17+
const text = await resp.text();
18+
strictEqual(text, 'Hello world!');
19+
} finally {
20+
server.stop();
21+
}
22+
}

0 commit comments

Comments
 (0)