@@ -1011,4 +1011,51 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
1011
1011
expect ( mock . done ( ) ) . toBe ( true ) ;
1012
1012
} ) ;
1013
1013
} ) ;
1014
+
1015
+ it ( "bubbles up AbortError if the request is aborted" , ( ) => {
1016
+ // AbortSignal and AbortController do not exist on
1017
+ // Node < 15. The main parts of their API have been
1018
+ // reproduced in the mocks below.
1019
+ class AbortSignal {
1020
+ abort = ( ) => {
1021
+ const e = new Error ( "" ) ;
1022
+ e . name = "AbortError" ;
1023
+ throw e ;
1024
+ } ;
1025
+
1026
+ addEventListener = ( ) => { } ;
1027
+ }
1028
+
1029
+ class AbortController {
1030
+ abort = ( ) => {
1031
+ this . signal . abort ( ) ;
1032
+ } ;
1033
+ signal = new AbortSignal ( ) ;
1034
+ }
1035
+ const abortController = new AbortController ( ) ;
1036
+ const mock = fetchMock . sandbox ( ) . post (
1037
+ "https://api.github.com/repos/octokit-fixture-org/release-assets/releases/tags/v1.0.0" ,
1038
+ new Promise ( ( ) => {
1039
+ abortController . abort ( ) ;
1040
+ } )
1041
+ ) ;
1042
+
1043
+ return request ( "POST /repos/{owner}/{repo}/releases/tags/{tag}" , {
1044
+ owner : "octokit-fixture-org" ,
1045
+ repo : "release-assets" ,
1046
+ tag : "v1.0.0" ,
1047
+ request : {
1048
+ fetch : mock ,
1049
+ signal : abortController . signal ,
1050
+ } ,
1051
+ headers : {
1052
+ "content-type" : "text/plain" ,
1053
+ } ,
1054
+ data : stringToArrayBuffer ( "Hello, world!\n" ) ,
1055
+ name : "test-upload.txt" ,
1056
+ label : "test" ,
1057
+ } ) . catch ( ( error ) => {
1058
+ expect ( error . name ) . toEqual ( "AbortError" ) ;
1059
+ } ) ;
1060
+ } ) ;
1014
1061
} ) ;
0 commit comments