@@ -86,7 +86,63 @@ test("'/data' should return the fixture payload we expect", async(tape) => {
86
86
tape . end ( ) ;
87
87
} ) ;
88
88
89
+ test ( "'/bundle/:name/:version' should return the bundle size" , async ( tape ) => {
90
+ const result = await get ( new URL ( "/bundle/flatstr/1.0.12" , HTTP_URL ) ) ;
91
+
92
+ tape . equal ( result . statusCode , 200 ) ;
93
+ tape . equal ( result . headers [ "content-type" ] , "application/json;charset=utf-8" ) ;
94
+ checkBundleResponse ( tape , result . data ) ;
95
+ } ) ;
96
+
97
+ test ( "'/bundle/:name/:version' should return an error if it fails" , async ( tape ) => {
98
+ tape . plan ( 2 ) ;
99
+ const wrongVersion = undefined ;
100
+
101
+ try {
102
+ await get ( new URL ( `/bundle/rimraf/${ wrongVersion } ` , HTTP_URL ) ) ;
103
+ }
104
+ catch ( error ) {
105
+ tape . equal ( error . statusCode , 404 ) ;
106
+ tape . equal ( error . data . error , "Not Found" ) ;
107
+ }
108
+
109
+ tape . end ( ) ;
110
+ } ) ;
111
+
112
+ test ( "'/bundle/:name' should return the bundle size of the last version" , async ( tape ) => {
113
+ const result = await get ( new URL ( "/bundle/flatstr" , HTTP_URL ) ) ;
114
+
115
+ tape . equal ( result . statusCode , 200 ) ;
116
+ tape . equal ( result . headers [ "content-type" ] , "application/json;charset=utf-8" ) ;
117
+ checkBundleResponse ( tape , result . data ) ;
118
+ } ) ;
119
+
120
+ test ( "'/bundle/:name' should return an error if it fails" , async ( tape ) => {
121
+ tape . plan ( 2 ) ;
122
+ const wrongPackageName = "br-br-br-brah" ;
123
+
124
+ try {
125
+ await get ( new URL ( `/bundle/${ wrongPackageName } ` , HTTP_URL ) ) ;
126
+ }
127
+ catch ( error ) {
128
+ tape . equal ( error . statusCode , 404 ) ;
129
+ tape . equal ( error . data . error , "Not Found" ) ;
130
+ }
131
+
132
+ tape . end ( ) ;
133
+ } ) ;
134
+
89
135
test ( "teardown" , ( tape ) => {
90
136
httpServer . server . close ( ) ;
91
137
tape . end ( ) ;
92
138
} ) ;
139
+
140
+ /**
141
+ * HELPERS
142
+ */
143
+
144
+ function checkBundleResponse ( tapeInstance , payload ) {
145
+ tapeInstance . ok ( payload . gzip ) ;
146
+ tapeInstance . ok ( payload . size ) ;
147
+ tapeInstance . ok ( payload . dependencySizes ) ;
148
+ }
0 commit comments