File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
test/cases/fetch-event-server Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ addEventListener ( "fetch" , ( event ) =>
2+ event . respondWith (
3+ ( async ( ) => {
4+ return new Response ( "Hello World" ) ;
5+ } ) ( ) ,
6+ ) ,
7+ ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments