File tree 4 files changed +50
-0
lines changed
4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,22 @@ polly.configure({
71
71
});
72
72
```
73
73
74
+ ## flushRequestsOnStop
75
+
76
+ _ Type_ : ` Boolean `
77
+ _ Default_ : ` false `
78
+
79
+ Await any unresolved requests handled by the polly instance
80
+ (via [ flush] ( api#flush ) ) when [ stop] ( api#stop ) is called.
81
+
82
+ ** Example**
83
+
84
+ ``` js
85
+ polly .configure ({
86
+ flushRequestsOnStop: true
87
+ });
88
+ ```
89
+
74
90
## expiresIn
75
91
76
92
_ Type_ : ` String `
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export default {
15
15
} ,
16
16
17
17
logging : false ,
18
+ flushRequestsOnStop : false ,
18
19
19
20
recordIfMissing : true ,
20
21
recordFailedRequests : false ,
Original file line number Diff line number Diff line change @@ -232,6 +232,10 @@ export default class Polly {
232
232
*/
233
233
async stop ( ) {
234
234
if ( this . mode !== MODES . STOPPED ) {
235
+ if ( this . config . flushRequestsOnStop ) {
236
+ await this . flush ( ) ;
237
+ }
238
+
235
239
this . disconnect ( ) ;
236
240
this . logger . disconnect ( ) ;
237
241
await ( this . persister && this . persister . persist ( ) ) ;
Original file line number Diff line number Diff line change @@ -169,6 +169,28 @@ describe('Unit | Polly', function() {
169
169
expect ( recognizedOptions . context ) . to . equal ( fakeContext ) ;
170
170
} ) ;
171
171
172
+ it ( 'calls flush when flushRequestsOnStop is enabled' , async function ( ) {
173
+ let polly = new Polly ( 'squawk' , { flushRequestsOnStop : false } ) ;
174
+ let flushCalled = false ;
175
+
176
+ polly . flush = async ( ) => {
177
+ flushCalled = true ;
178
+ } ;
179
+
180
+ await polly . stop ( ) ;
181
+ expect ( flushCalled ) . to . be . false ;
182
+
183
+ polly = new Polly ( 'squawk' , { flushRequestsOnStop : true } ) ;
184
+ flushCalled = false ;
185
+
186
+ polly . flush = async ( ) => {
187
+ flushCalled = true ;
188
+ } ;
189
+
190
+ await polly . stop ( ) ;
191
+ expect ( flushCalled ) . to . be . true ;
192
+ } ) ;
193
+
172
194
describe ( 'configure' , function ( ) {
173
195
setupPolly ( ) ;
174
196
@@ -481,6 +503,13 @@ describe('Unit | Polly', function() {
481
503
expect ( this . polly . disconnect ( ) ) ;
482
504
expect ( disconnects . length ) . to . equal ( 2 ) ;
483
505
} ) ;
506
+
507
+ it ( '.flush()' , async function ( ) {
508
+ const promise = this . polly . flush ( ) ;
509
+
510
+ expect ( promise ) . to . be . a ( 'promise' ) ;
511
+ await promise ;
512
+ } ) ;
484
513
} ) ;
485
514
486
515
describe ( 'Class Methods & Events' , function ( ) {
You can’t perform that action at this time.
0 commit comments