11import { describe , expect , it } from "bun:test" ;
22import "harness" ;
3- import { isWindows } from "harness" ;
3+ import { bunEnv , bunExe , isWindows } from "harness" ;
44
55// TODO: on Windows, these tests fail.
66// This feature is mostly meant for serverless JS environments, so we can no-op it on Windows.
7- describe . todoIf ( isWindows ) ( "fetch.preconnect" , ( ) => {
7+ describe . concurrent . todoIf ( isWindows ) ( "fetch.preconnect" , ( ) => {
88 it ( "fetch.preconnect works" , async ( ) => {
9- const { promise, resolve } = Promise . withResolvers ( ) ;
9+ const { promise, resolve } = Promise . withResolvers < Bun . Socket > ( ) ;
1010 using listener = Bun . listen ( {
1111 port : 0 ,
1212 hostname : "localhost" ,
@@ -29,12 +29,12 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
2929 expect ( response . status ) . toBe ( 200 ) ;
3030 } ) ;
3131
32- describe ( "doesn't break the request when" , ( ) => {
32+ describe . concurrent ( "doesn't break the request when" , ( ) => {
3333 for ( let endOrTerminate of [ "end" , "terminate" , "shutdown" ] ) {
3434 describe ( endOrTerminate , ( ) => {
3535 for ( let at of [ "before" , "middle" , "after" ] ) {
3636 it ( at , async ( ) => {
37- let { promise, resolve } = Promise . withResolvers ( ) ;
37+ let { promise, resolve } = Promise . withResolvers < Bun . Socket > ( ) ;
3838 using listener = Bun . listen ( {
3939 port : 0 ,
4040 hostname : "localhost" ,
@@ -48,7 +48,7 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
4848 } ) ;
4949 fetch . preconnect ( `http://localhost:${ listener . port } ` ) ;
5050 let socket = await promise ;
51- ( { promise, resolve } = Promise . withResolvers ( ) ) ;
51+ ( { promise, resolve } = Promise . withResolvers < Bun . Socket > ( ) ) ;
5252 if ( at === "before" ) {
5353 await Bun . sleep ( 16 ) ;
5454 socket [ endOrTerminate ] ( ) ;
@@ -86,7 +86,7 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
8686 } ) ;
8787
8888 it ( "--fetch-preconnect works" , async ( ) => {
89- const { promise, resolve } = Promise . withResolvers ( ) ;
89+ const { promise, resolve } = Promise . withResolvers < void > ( ) ;
9090 using listener = Bun . listen ( {
9191 port : 0 ,
9292 hostname : "localhost" ,
@@ -102,7 +102,13 @@ describe.todoIf(isWindows)("fetch.preconnect", () => {
102102 } ) ;
103103
104104 // Do --fetch-preconnect, but don't actually send a request.
105- expect ( [ `--fetch-preconnect=http://localhost:${ listener . port } ` , "--eval" , "Bun.sleep(64)" ] ) . toRun ( ) ;
105+ await using proc = Bun . spawn ( {
106+ cmd : [ bunExe ( ) , `--fetch-preconnect=http://localhost:${ listener . port } ` , "--eval" , "Bun.sleep(64)" ] ,
107+ stdio : [ "inherit" , "inherit" , "inherit" ] ,
108+ env : bunEnv ,
109+ } ) ;
110+
111+ expect ( await proc . exited ) . toBe ( 0 ) ;
106112
107113 await promise ;
108114 } ) ;
0 commit comments