@@ -71,19 +71,43 @@ test("canonical GitHub App signer converts PKCS1 private keys to PKCS8", async (
7171
7272test ( "worker GitHub App call sites preserve plain error messages" , async ( ) => {
7373 const originalFetch = globalThis . fetch ;
74+ const originalSetTimeout = globalThis . setTimeout ;
7475 const { privateKey } = generateKeyPairSync ( "rsa" , {
7576 modulusLength : 2048 ,
7677 privateKeyEncoding : { type : "pkcs8" , format : "pem" } ,
7778 publicKeyEncoding : { type : "spki" , format : "pem" } ,
7879 } ) ;
80+ const fetchFailure = new TypeError ( "fetch failed" ) ;
81+ const abortFailure = new DOMException ( "request aborted" , "AbortError" ) ;
7982 const failures = [
8083 {
81- fetch : async ( ) => {
82- throw new DOMException ( "request aborted" , "AbortError" ) ;
84+ fetch : async ( _input : RequestInfo | URL , init ?: RequestInit ) => {
85+ assert . equal ( init ?. signal ?. aborted , true ) ;
86+ throw new DOMException ( "request timed out" , "AbortError" ) ;
8387 } ,
88+ setTimeout : ( ( callback : TimerHandler ) => {
89+ if ( typeof callback === "function" ) callback ( ) ;
90+ return 0 ;
91+ } ) as typeof globalThis . setTimeout ,
8492 message : "GitHub App installation timed out" ,
8593 constructor : Error ,
8694 } ,
95+ {
96+ fetch : async ( ) => {
97+ throw fetchFailure ;
98+ } ,
99+ message : "fetch failed" ,
100+ constructor : TypeError ,
101+ original : fetchFailure ,
102+ } ,
103+ {
104+ fetch : async ( ) => {
105+ throw abortFailure ;
106+ } ,
107+ message : "request aborted" ,
108+ constructor : DOMException ,
109+ original : abortFailure ,
110+ } ,
87111 {
88112 fetch : async ( ) =>
89113 new Response ( JSON . stringify ( { message : "upstream unavailable" } ) , { status : 503 } ) ,
@@ -100,6 +124,7 @@ test("worker GitHub App call sites preserve plain error messages", async () => {
100124 try {
101125 for ( const failure of failures ) {
102126 globalThis . fetch = failure . fetch ;
127+ globalThis . setTimeout = failure . setTimeout || originalSetTimeout ;
103128 await assert . rejects (
104129 worker . fetch ( workerGithubWebhookRequest ( ) , {
105130 CLAWSWEEPER_APP_CLIENT_ID : "Iv23worker-errors" ,
@@ -109,12 +134,14 @@ test("worker GitHub App call sites preserve plain error messages", async () => {
109134 ( error : Error ) => {
110135 assert . equal ( error . constructor , failure . constructor ) ;
111136 assert . equal ( error . message , failure . message ) ;
137+ if ( failure . original ) assert . equal ( error , failure . original ) ;
112138 return true ;
113139 } ,
114140 ) ;
115141 }
116142 } finally {
117143 globalThis . fetch = originalFetch ;
144+ globalThis . setTimeout = originalSetTimeout ;
118145 }
119146} ) ;
120147
0 commit comments