11import { APIError } from "../../parse" ;
22import { retryOnAPIFailure } from "../../utils/retry" ;
3+ import { mockConsoleMethods } from "../helpers/mock-console" ;
34
45describe ( "retryOnAPIFailure" , ( ) => {
6+ const std = mockConsoleMethods ( ) ;
7+
58 it ( "should retry 5xx errors and succeed if the 3rd try succeeds" , async ( ) => {
69 let attempts = 0 ;
710
@@ -12,6 +15,16 @@ describe("retryOnAPIFailure", () => {
1215 }
1316 } ) ;
1417 expect ( attempts ) . toBe ( 3 ) ;
18+ expect ( std ) . toMatchInlineSnapshot ( `
19+ Object {
20+ "debug": "",
21+ "err": "",
22+ "info": "Retrying API call after error...
23+ Retrying API call after error...",
24+ "out": "",
25+ "warn": "",
26+ }
27+ ` ) ;
1528 } ) ;
1629
1730 it ( "should throw 5xx error after all retries fail" , async ( ) => {
@@ -24,6 +37,17 @@ describe("retryOnAPIFailure", () => {
2437 } )
2538 ) . rejects . toMatchInlineSnapshot ( `[APIError: 500 error]` ) ;
2639 expect ( attempts ) . toBe ( 3 ) ;
40+ expect ( std ) . toMatchInlineSnapshot ( `
41+ Object {
42+ "debug": "",
43+ "err": "",
44+ "info": "Retrying API call after error...
45+ Retrying API call after error...
46+ Retrying API call after error...",
47+ "out": "",
48+ "warn": "",
49+ }
50+ ` ) ;
2751 } ) ;
2852
2953 it ( "should not retry non-5xx errors" , async ( ) => {
@@ -36,6 +60,15 @@ describe("retryOnAPIFailure", () => {
3660 } )
3761 ) . rejects . toMatchInlineSnapshot ( `[APIError: 401 error]` ) ;
3862 expect ( attempts ) . toBe ( 1 ) ;
63+ expect ( std ) . toMatchInlineSnapshot ( `
64+ Object {
65+ "debug": "",
66+ "err": "",
67+ "info": "",
68+ "out": "",
69+ "warn": "",
70+ }
71+ ` ) ;
3972 } ) ;
4073
4174 it ( "should retry TypeError" , async ( ) => {
@@ -48,6 +81,17 @@ describe("retryOnAPIFailure", () => {
4881 } )
4982 ) . rejects . toMatchInlineSnapshot ( `[TypeError: type error]` ) ;
5083 expect ( attempts ) . toBe ( 3 ) ;
84+ expect ( std ) . toMatchInlineSnapshot ( `
85+ Object {
86+ "debug": "",
87+ "err": "",
88+ "info": "Retrying API call after error...
89+ Retrying API call after error...
90+ Retrying API call after error...",
91+ "out": "",
92+ "warn": "",
93+ }
94+ ` ) ;
5195 } ) ;
5296
5397 it ( "should not retry other errors" , async ( ) => {
@@ -60,6 +104,15 @@ describe("retryOnAPIFailure", () => {
60104 } )
61105 ) . rejects . toMatchInlineSnapshot ( `[Error: some error]` ) ;
62106 expect ( attempts ) . toBe ( 1 ) ;
107+ expect ( std ) . toMatchInlineSnapshot ( `
108+ Object {
109+ "debug": "",
110+ "err": "",
111+ "info": "",
112+ "out": "",
113+ "warn": "",
114+ }
115+ ` ) ;
63116 } ) ;
64117
65118 it ( "should retry custom APIError implementation with non-5xx error" , async ( ) => {
@@ -81,5 +134,16 @@ describe("retryOnAPIFailure", () => {
81134 ) . rejects . toMatchInlineSnapshot ( `[CustomAPIError: 401 error]` ) ;
82135 expect ( attempts ) . toBe ( 3 ) ;
83136 expect ( checkedCustomIsRetryable ) . toBe ( true ) ;
137+ expect ( std ) . toMatchInlineSnapshot ( `
138+ Object {
139+ "debug": "",
140+ "err": "",
141+ "info": "Retrying API call after error...
142+ Retrying API call after error...
143+ Retrying API call after error...",
144+ "out": "",
145+ "warn": "",
146+ }
147+ ` ) ;
84148 } ) ;
85149} ) ;
0 commit comments