This repository was archived by the owner on Feb 13, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,7 @@ class Analytics {
53
53
enumerable : true ,
54
54
value : typeof options . enable === 'boolean' ? options . enable : true
55
55
} )
56
- this . axiosClient = axios . create ( )
57
- axiosRetry ( this . axiosClient , {
56
+ axiosRetry ( this . axiosInstance , {
58
57
retries : options . retryCount || 3 ,
59
58
retryCondition : this . _isErrorRetryable ,
60
59
retryDelay : axiosRetry . exponentialDelay
@@ -266,20 +265,17 @@ class Analytics {
266
265
}
267
266
268
267
const req = {
269
- method : 'POST' ,
270
- url : `${ this . host } ${ this . path } ` ,
271
268
auth : {
272
269
username : this . writeKey
273
270
} ,
274
- data,
275
271
headers
276
272
}
277
273
278
274
if ( this . timeout ) {
279
275
req . timeout = typeof this . timeout === 'string' ? ms ( this . timeout ) : this . timeout
280
276
}
281
277
282
- this . axiosClient ( req )
278
+ this . axiosInstance . post ( ` ${ this . host } ${ this . path } ` , data , req )
283
279
. then ( ( ) => done ( ) )
284
280
. catch ( err => {
285
281
if ( err . response ) {
Original file line number Diff line number Diff line change @@ -606,6 +606,30 @@ test('ensure that failed requests are not retried forever', async t => {
606
606
await t . throws ( client . flush ( ) )
607
607
} )
608
608
609
+ test ( 'ensure we can pass our own axios instance' , async t => {
610
+ const axios = require ( 'axios' )
611
+ const myAxiosInstance = axios . create ( )
612
+ const stubAxiosPost = stub ( myAxiosInstance , 'post' ) . resolves ( )
613
+ const client = createClient ( {
614
+ axiosInstance : myAxiosInstance ,
615
+ host : 'https://my-dummy-host.com' ,
616
+ path : '/test/path'
617
+ } )
618
+
619
+ const callback = spy ( )
620
+ client . queue = [
621
+ {
622
+ message : 'something' ,
623
+ callback
624
+ }
625
+ ]
626
+
627
+ client . flush ( )
628
+
629
+ t . true ( stubAxiosPost . called )
630
+ t . true ( stubAxiosPost . alwaysCalledWith ( 'https://my-dummy-host.com/test/path' ) )
631
+ } )
632
+
609
633
test ( 'ensure other axios clients are not impacted by axios-retry' , async t => {
610
634
let client = createClient ( ) // eslint-disable-line
611
635
const axios = require ( 'axios' )
You can’t perform that action at this time.
0 commit comments