@@ -27,6 +27,32 @@ afterAll(async() => {
2727} ) ;
2828
2929describe ( "stream" , ( ) => {
30+ it ( "should use callback dispatcher to init headers/statusCode etc." , async ( ) => {
31+ const fileDestination = path . join ( kDownloadPath , "i18n-main.tar.gz" ) ;
32+ const repositoryURL = new URL ( "NodeSecure/i18n/archive/main.tar.gz" , kGithubURL ) ;
33+
34+ const cursor = httpie . stream ( "GET" , repositoryURL , {
35+ headers : {
36+ "User-Agent" : "httpie" ,
37+ "Accept-Encoding" : "gzip, deflate"
38+ } ,
39+ maxRedirections : 1
40+ } ) ;
41+
42+ let contentType = "" ;
43+ let code = 0 ;
44+ await cursor ( ( { headers, statusCode } ) => {
45+ contentType = headers [ "content-type" ] as string ;
46+ code = statusCode ;
47+
48+ return createWriteStream ( fileDestination ) ;
49+ } ) ;
50+
51+ expect ( existsSync ( fileDestination ) ) . toStrictEqual ( true ) ;
52+ expect ( contentType ) . toBe ( "application/x-gzip" ) ;
53+ expect ( code ) . toBe ( 200 ) ;
54+ } ) ;
55+
3056 it ( "should fetch a .tar.gz of a given github repository" , async ( ) => {
3157 const fileDestination = path . join ( kDownloadPath , "i18n-main.tar.gz" ) ;
3258 const repositoryURL = new URL ( "NodeSecure/i18n/archive/main.tar.gz" , kGithubURL ) ;
@@ -37,15 +63,15 @@ describe("stream", () => {
3763 "Accept-Encoding" : "gzip, deflate"
3864 } ,
3965 maxRedirections : 1
40- } ) ( createWriteStream ( fileDestination ) ) ;
66+ } ) ( ( ) => createWriteStream ( fileDestination ) ) ;
4167
4268 expect ( existsSync ( fileDestination ) ) . toStrictEqual ( true ) ;
4369 } ) ;
4470
4571 it ( "should fetch the HTML home from the local fastify server" , async ( ) => {
4672 const fileDestination = path . join ( kDownloadPath , "home.html" ) ;
4773
48- await httpie . stream ( "GET" , "/stream/home" ) ( createWriteStream ( fileDestination ) ) ;
74+ await httpie . stream ( "GET" , "/stream/home" ) ( ( ) => createWriteStream ( fileDestination ) ) ;
4975
5076 expect ( existsSync ( fileDestination ) ) . toStrictEqual ( true ) ;
5177 const [ contentA , contentB ] = await Promise . all ( [
0 commit comments