Comparing version 3.0.0 to 3.1.0
@@ -0,1 +1,5 @@ | ||
# 3.1.0 | ||
Adds initial Typescript support. | ||
# 3.0.0 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "cachios", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Simple axios cache wrapper using node-cache", | ||
@@ -34,12 +34,12 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"axios": "^0.18.0 || ^0.19.0 || ^0.20.0 || ^0.21.0", | ||
"node-cache": "^4.1.1 || ^5.0.0", | ||
"axios": "^0.21.0 || ^0.20.0 || ^0.19.0 || ^0.18.0", | ||
"node-cache": "^5.0.0 || ^4.1.1", | ||
"object-hash": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"axios-mock-adapter": "^1.20.0", | ||
"coveralls": "^3.0.0", | ||
"express": "^4.16.2", | ||
"jest": "^26.6.3", | ||
"moxios": "^0.4.0" | ||
"jest": "^27.2.5" | ||
} | ||
} |
@@ -12,1 +12,3 @@ var axios = require('axios'); | ||
module.exports = instance; | ||
// better `import cachios from 'cachios';` typescript support: | ||
module.exports.default = instance; |
const cachios = require('./../src'); | ||
const axios = require('axios'); | ||
const moxios = require('moxios'); | ||
const MockAdapter = require('axios-mock-adapter'); | ||
describe('cachios cancelling', () => { | ||
let mock; | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
mock = new MockAdapter(axios); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
mock.reset(); | ||
}); | ||
@@ -42,5 +44,3 @@ | ||
moxios.stubRequest(url, { | ||
status: 200, | ||
}); | ||
mock.onGet(url).reply(200); | ||
@@ -47,0 +47,0 @@ try { |
const cachios = require('./../src'); | ||
const axios = require('axios'); | ||
const moxios = require('moxios'); | ||
const MockAdapter = require('axios-mock-adapter'); | ||
@@ -20,8 +20,10 @@ const datalessMethods = [ | ||
describe('cachios', () => { | ||
let mock; | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
mock = new MockAdapter(axios); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
mock.reset(); | ||
}); | ||
@@ -43,10 +45,4 @@ | ||
mock.onAny(url).replyOnce(200); | ||
cachiosInstance[method](url).then(() => { done(); }); | ||
moxios.wait(function() { | ||
moxios.requests.mostRecent().respondWith({ | ||
status: 200, | ||
response: {}, | ||
}); | ||
}); | ||
}); | ||
@@ -59,2 +55,6 @@ | ||
mock.onAny(url).replyOnce(200, { | ||
time: time, | ||
}); | ||
let promise = cachiosInstance[method](url, { | ||
@@ -64,21 +64,11 @@ ttl: 60, | ||
moxios.wait(function() { | ||
let request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: { | ||
time: time, | ||
} | ||
}); | ||
for(let i = 0; i < 10; i += 1) { | ||
promise = promise.then(() => cachiosInstance[method](url, { | ||
ttl: 60, | ||
}).then((resp) => { | ||
expect(resp.data.time).toBe(time); | ||
})); | ||
} | ||
for(let i = 0; i < 10; i += 1) { | ||
promise = promise.then(() => cachiosInstance[method](url, { | ||
ttl: 60, | ||
}).then((resp) => { | ||
expect(resp.data.time).toBe(time); | ||
})); | ||
} | ||
promise.then(done); | ||
}); | ||
promise.then(done); | ||
}); | ||
@@ -97,10 +87,4 @@ }); | ||
mock.onAny(url).replyOnce(200); | ||
cachiosInstance[method](url, postData).then(() => { done(); }); | ||
moxios.wait(function() { | ||
moxios.requests.mostRecent().respondWith({ | ||
status: 200, | ||
response: {}, | ||
}); | ||
}); | ||
}); | ||
@@ -116,2 +100,6 @@ | ||
mock.onAny(url).replyOnce(200, { | ||
time: time, | ||
}); | ||
let promise = cachiosInstance[method](url, postData, { | ||
@@ -121,25 +109,14 @@ ttl: 60, | ||
moxios.wait(function() { | ||
let request = moxios.requests.mostRecent(); | ||
request.respondWith({ | ||
status: 200, | ||
response: { | ||
time: time, | ||
} | ||
}); | ||
for(let i = 0; i < 10; i += 1) { | ||
promise = promise.then(() => cachiosInstance[method](url, postData, { | ||
ttl: 60, | ||
}).then((resp) => { | ||
expect(resp.data.time).toBe(time); | ||
})); | ||
} | ||
for(let i = 0; i < 10; i += 1) { | ||
promise = promise.then(() => cachiosInstance[method](url, postData, { | ||
ttl: 60, | ||
}).then((resp) => { | ||
expect(resp.data.time).toBe(time); | ||
})); | ||
} | ||
promise.then(done); | ||
}); | ||
promise.then(done); | ||
}); | ||
}); | ||
}); | ||
}); |
const cachios = require('./../src'); | ||
const axios = require('axios'); | ||
const moxios = require('moxios'); | ||
const MockAdapter = require('axios-mock-adapter'); | ||
describe('cachios.getCacheIdentifier', () => { | ||
let mock; | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
mock = new MockAdapter(axios); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
mock.reset(); | ||
}); | ||
@@ -28,23 +30,14 @@ | ||
mock.onGet(url).replyOnce(200); | ||
// always return the same identifier | ||
instance.getCacheIdentifier = () => 42; | ||
// this is a bit of an anti-pattern here: | ||
// we only respond to the first request with moxios. | ||
// so, if this was not working (and a second request was attempted), | ||
// we only respond to the first request with the mock adapter. | ||
// so, if caching was not working and a second request was attempted, | ||
// the test would timeout. | ||
instance.get(url) | ||
.then(() => instance.get(otherUrl)) | ||
.then(() => done()); | ||
moxios.wait(() => { | ||
moxios.requests.mostRecent() | ||
.respondWith({ | ||
status: 200, | ||
response: { | ||
foo: 'bar', | ||
}, | ||
}); | ||
}); | ||
.then(() => instance.get(otherUrl)) | ||
.then(() => done()); | ||
}); | ||
}); |
const cachios = require('./../src'); | ||
const axios = require('axios'); | ||
const moxios = require('moxios'); | ||
const MockAdapter = require('axios-mock-adapter'); | ||
describe('cachios.getResponseCopy', () => { | ||
let mock; | ||
beforeEach(() => { | ||
moxios.install(axios); | ||
mock = new MockAdapter(axios); | ||
}); | ||
afterEach(() => { | ||
moxios.uninstall(axios); | ||
mock.reset(); | ||
}); | ||
@@ -27,2 +29,6 @@ | ||
mock.onGet(url).replyOnce(200, { | ||
foo: 'bar', | ||
}); | ||
instance.getResponseCopy = (resp) => ({ | ||
@@ -46,13 +52,3 @@ status: resp.status, | ||
.then(() => done()); | ||
moxios.wait(() => { | ||
moxios.requests.mostRecent() | ||
.respondWith({ | ||
status: 200, | ||
response: { | ||
foo: 'bar', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
40338
24
753