Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class Analytics {
enumerable: true,
value: typeof options.enable === 'boolean' ? options.enable : true
})
this.axiosClient = axios.create()
axiosRetry(this.axiosClient, {
axiosRetry(this.axiosInstance, {
retries: options.retryCount || 3,
retryCondition: this._isErrorRetryable,
retryDelay: axiosRetry.exponentialDelay
Expand Down Expand Up @@ -266,20 +265,17 @@ class Analytics {
}

const req = {
method: 'POST',
url: `${this.host}${this.path}`,
auth: {
username: this.writeKey
},
data,
headers
}

if (this.timeout) {
req.timeout = typeof this.timeout === 'string' ? ms(this.timeout) : this.timeout
}

this.axiosClient(req)
this.axiosInstance.post(`${this.host}${this.path}`, data, req)
.then(() => done())
.catch(err => {
if (err.response) {
Expand Down
24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,30 @@ test('ensure that failed requests are not retried forever', async t => {
await t.throws(client.flush())
})

test('ensure we can pass our own axios instance', async t => {
const axios = require('axios')
const myAxiosInstance = axios.create()
const stubAxiosPost = stub(myAxiosInstance, 'post').resolves()
const client = createClient({
axiosInstance: myAxiosInstance,
host: 'https://my-dummy-host.com',
path: '/test/path'
})

const callback = spy()
client.queue = [
{
message: 'something',
callback
}
]

client.flush()

t.true(stubAxiosPost.called)
t.true(stubAxiosPost.alwaysCalledWith('https://my-dummy-host.com/test/path'))
})

test('ensure other axios clients are not impacted by axios-retry', async t => {
let client = createClient() // eslint-disable-line
const axios = require('axios')
Expand Down