@lifeomic/bitrise
Advanced tools
Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "@lifeomic/bitrise", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Bitrise API client", | ||
@@ -24,2 +24,3 @@ "main": "src/client.js", | ||
"axios": "^0.18.0", | ||
"axios-retry": "^3.1.1", | ||
"lodash": "^4.17.10" | ||
@@ -33,2 +34,3 @@ }, | ||
"luxon": "^1.3.1", | ||
"nock": "^9.4.2", | ||
"nyc": "^12.0.2", | ||
@@ -35,0 +37,0 @@ "sinon": "^6.1.0", |
const app = require('./app'); | ||
const assert = require('assert'); | ||
const axios = require('axios'); | ||
const axiosRetry = require('axios-retry'); | ||
@@ -13,2 +14,4 @@ module.exports = ({ token }) => { | ||
axiosRetry(client, { retryDelay: axiosRetry.exponentialDelay }); | ||
const instance = {}; | ||
@@ -15,0 +18,0 @@ instance.app = ({ slug }) => app({ client, slug }); |
const axios = require('axios'); | ||
const client = require('..'); | ||
const nock = require('nock'); | ||
const sinon = require('sinon'); | ||
@@ -7,3 +8,12 @@ const test = require('ava'); | ||
test('an api token is required', (test) => { | ||
test.beforeEach(() => { | ||
nock.disableNetConnect(); | ||
}); | ||
test.afterEach(() => { | ||
nock.enableNetConnect(); | ||
nock.cleanAll(); | ||
}); | ||
test.serial('an api token is required', (test) => { | ||
test.throws(() => client()); | ||
@@ -15,3 +25,3 @@ test.throws(() => client({})); | ||
test.serial('a client is authenticated', (test) => { | ||
const create = sinon.stub(axios, 'create'); | ||
const create = sinon.spy(axios, 'create'); | ||
const token = uuid(); | ||
@@ -36,3 +46,5 @@ | ||
test.serial('a client can create an app', async (test) => { | ||
const axiosInstance = { post: sinon.stub().rejects(new Error('fake')) }; | ||
const axiosInstance = axios.create(); | ||
sinon.stub(axiosInstance, 'post').rejects(new Error('fake')); | ||
const create = sinon.stub(axios, 'create').returns(axiosInstance); | ||
@@ -57,1 +69,44 @@ const slug = uuid(); | ||
}); | ||
test.serial('a client retries requests', async (test) => { | ||
const create = sinon.spy(axios, 'create'); | ||
const token = uuid(); | ||
nock('http://localhost') | ||
.get('/error').replyWithError('boom') | ||
.get('/error').reply(500) | ||
.get('/error').reply(200, 'success!'); | ||
try { | ||
const instance = client({ token }); | ||
test.truthy(instance); | ||
sinon.assert.calledOnce(create); | ||
const httpClient = create.firstCall.returnValue; | ||
const response = await httpClient.get('http://localhost/error'); | ||
test.is(response.data, 'success!'); | ||
} finally { | ||
create.restore(); | ||
} | ||
}); | ||
test.serial('a client gives up after too many retries', async (test) => { | ||
const create = sinon.spy(axios, 'create'); | ||
const token = uuid(); | ||
nock('http://localhost') | ||
.get('/error').replyWithError('boom') | ||
.get('/error').thrice().reply(500); | ||
try { | ||
const instance = client({ token }); | ||
test.truthy(instance); | ||
sinon.assert.calledOnce(create); | ||
const httpClient = create.firstCall.returnValue; | ||
const { response } = await test.throws(httpClient.get('http://localhost/error')); | ||
test.is(response.status, 500); | ||
} finally { | ||
create.restore(); | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186956
682
3
9
1
+ Addedaxios-retry@^3.1.1
+ Added@babel/runtime@7.25.9(transitive)
+ Addedaxios-retry@3.9.1(transitive)
+ Addedis-retry-allowed@2.2.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)