@@ -191,60 +191,60 @@ describe('cli notices', () => {
191191 expect ( result ) . toEqual ( [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] ) ;
192192 } ) ;
193193
194- test ( 'returns empty array when the server returns an unexpected status code' , async ( ) => {
195- const result = await mockCall ( 500 , {
194+ test ( 'returns appropriate error when the server returns an unexpected status code' , async ( ) => {
195+ const result = mockCall ( 500 , {
196196 notices : [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] ,
197197 } ) ;
198198
199- expect ( result ) . toEqual ( [ ] ) ;
199+ await expect ( result ) . rejects . toThrow ( / 5 0 0 / ) ;
200200 } ) ;
201201
202- test ( 'returns empty array when the server returns an unexpected structure' , async ( ) => {
203- const result = await mockCall ( 200 , {
202+ test ( 'returns appropriate error when the server returns an unexpected structure' , async ( ) => {
203+ const result = mockCall ( 200 , {
204204 foo : [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] ,
205205 } ) ;
206206
207- expect ( result ) . toEqual ( [ ] ) ;
207+ await expect ( result ) . rejects . toThrow ( / k e y i s m i s s i n g / ) ;
208208 } ) ;
209209
210- test ( 'returns empty array when the server returns invalid json' , async ( ) => {
211- const result = await mockCall ( 200 , '-09aiskjkj838' ) ;
210+ test ( 'returns appropriate error when the server returns invalid json' , async ( ) => {
211+ const result = mockCall ( 200 , '-09aiskjkj838' ) ;
212212
213- expect ( result ) . toEqual ( [ ] ) ;
213+ await expect ( result ) . rejects . toThrow ( / F a i l e d t o p a r s e / ) ;
214214 } ) ;
215215
216- test ( 'returns empty array when HTTPS call throws' , async ( ) => {
216+ test ( 'returns appropriate error when HTTPS call throws' , async ( ) => {
217217 const mockGet = jest . spyOn ( https , 'get' )
218218 . mockImplementation ( ( ) => { throw new Error ( 'No connection' ) ; } ) ;
219219
220- const result = await dataSource . fetch ( ) ;
220+ const result = dataSource . fetch ( ) ;
221221
222- expect ( result ) . toEqual ( [ ] ) ;
222+ await expect ( result ) . rejects . toThrow ( / N o c o n n e c t i o n / ) ;
223223
224224 mockGet . mockRestore ( ) ;
225225 } ) ;
226226
227- test ( 'returns empty array when the request has an error' , async ( ) => {
227+ test ( 'returns appropriate error when the request has an error' , async ( ) => {
228228 nock ( 'https://cli.cdk.dev-tools.aws.dev' )
229229 . get ( '/notices.json' )
230230 . replyWithError ( 'DNS resolution failed' ) ;
231231
232- const result = await dataSource . fetch ( ) ;
232+ const result = dataSource . fetch ( ) ;
233233
234- expect ( result ) . toEqual ( [ ] ) ;
234+ await expect ( result ) . rejects . toThrow ( / D N S r e s o l u t i o n f a i l e d / ) ;
235235 } ) ;
236236
237- test ( 'returns empty array when the connection stays idle for too long' , async ( ) => {
237+ test ( 'returns appropriate error when the connection stays idle for too long' , async ( ) => {
238238 nock ( 'https://cli.cdk.dev-tools.aws.dev' )
239239 . get ( '/notices.json' )
240240 . delayConnection ( 3500 )
241241 . reply ( 200 , {
242242 notices : [ BASIC_NOTICE ] ,
243243 } ) ;
244244
245- const result = await dataSource . fetch ( ) ;
245+ const result = dataSource . fetch ( ) ;
246246
247- expect ( result ) . toEqual ( [ ] ) ;
247+ await expect ( result ) . rejects . toThrow ( / t i m e d o u t / ) ;
248248 } ) ;
249249
250250 test ( 'returns empty array when the request takes too long to finish' , async ( ) => {
@@ -255,9 +255,9 @@ describe('cli notices', () => {
255255 notices : [ BASIC_NOTICE ] ,
256256 } ) ;
257257
258- const result = await dataSource . fetch ( ) ;
258+ const result = dataSource . fetch ( ) ;
259259
260- expect ( result ) . toEqual ( [ ] ) ;
260+ await expect ( result ) . rejects . toThrow ( / t i m e d o u t / ) ;
261261 } ) ;
262262
263263 function mockCall ( statusCode : number , body : any ) : Promise < Notice [ ] > {
@@ -313,6 +313,10 @@ describe('cli notices', () => {
313313 test ( 'retrieves data from the delegate when the file cannot be read' , async ( ) => {
314314 const debugSpy = jest . spyOn ( logging , 'debug' ) ;
315315
316+ if ( fs . existsSync ( 'does-not-exist.json' ) ) {
317+ fs . unlinkSync ( 'does-not-exist.json' ) ;
318+ }
319+
316320 const dataSource = dataSourceWithDelegateReturning ( freshData , 'does-not-exist.json' ) ;
317321
318322 const notices = await dataSource . fetch ( ) ;
@@ -335,6 +339,20 @@ describe('cli notices', () => {
335339 expect ( notices ) . toEqual ( freshData ) ;
336340 } ) ;
337341
342+ test ( 'error in delegate gets turned into empty result by cached source' , async ( ) => {
343+ // GIVEN
344+ const delegate = {
345+ fetch : jest . fn ( ) . mockRejectedValue ( new Error ( 'fetching failed' ) ) ,
346+ } ;
347+ const dataSource = new CachedDataSource ( fileName , delegate , true ) ;
348+
349+ // WHEN
350+ const notices = await dataSource . fetch ( ) ;
351+
352+ // THEN
353+ expect ( notices ) . toEqual ( [ ] ) ;
354+ } ) ;
355+
338356 function dataSourceWithDelegateReturning ( notices : Notice [ ] , file : string = fileName , ignoreCache : boolean = false ) {
339357 const delegate = {
340358 fetch : jest . fn ( ) ,
0 commit comments