2018-12-02 14:39:52 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
|
|
|
import * as smartcache from '../ts/index';
|
|
|
|
import * as smartdelay from '@pushrocks/smartdelay';
|
2018-07-12 19:32:20 +00:00
|
|
|
|
2018-07-12 21:52:06 +00:00
|
|
|
let smartcacheInstance: smartcache.SmartCache;
|
2018-07-12 19:32:20 +00:00
|
|
|
|
2018-12-02 14:39:52 +00:00
|
|
|
tap.test('should create a valid instance of SmartCache', async () => {
|
2018-07-12 21:52:06 +00:00
|
|
|
smartcacheInstance = new smartcache.SmartCache();
|
|
|
|
expect(smartcacheInstance).to.be.instanceof(smartcache.SmartCache);
|
|
|
|
});
|
|
|
|
|
2018-12-02 14:39:52 +00:00
|
|
|
tap.test('try to get async responses', async () => {
|
2018-07-12 21:52:06 +00:00
|
|
|
const getResponse = async () => {
|
|
|
|
const response = await smartcacheInstance
|
|
|
|
.cacheReturn(async () => {
|
2020-02-03 20:08:57 +00:00
|
|
|
console.log('function 1 ran');
|
2018-12-02 14:39:52 +00:00
|
|
|
return 'hello';
|
2018-07-12 21:52:06 +00:00
|
|
|
}, 1000)
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2018-12-02 14:39:52 +00:00
|
|
|
console.log('response is:');
|
2018-07-12 21:52:06 +00:00
|
|
|
console.log(response);
|
|
|
|
};
|
2018-07-12 19:32:20 +00:00
|
|
|
|
2018-07-12 21:52:06 +00:00
|
|
|
const getResponse2 = async () => {
|
|
|
|
const response = await smartcacheInstance
|
|
|
|
.cacheReturn(async () => {
|
2018-12-02 14:39:52 +00:00
|
|
|
console.log('function 2 ran');
|
2020-02-03 20:08:57 +00:00
|
|
|
return 'hello there!';
|
2018-07-12 21:52:06 +00:00
|
|
|
}, 1000)
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
2018-12-02 14:39:52 +00:00
|
|
|
console.log('response is:');
|
2018-07-12 21:52:06 +00:00
|
|
|
console.log(response);
|
|
|
|
};
|
|
|
|
|
2020-02-03 20:08:57 +00:00
|
|
|
await getResponse();
|
|
|
|
await getResponse();
|
|
|
|
await getResponse2();
|
|
|
|
await getResponse2();
|
|
|
|
await smartdelay.delayFor(2000).then(async () => {
|
2018-12-02 14:34:05 +00:00
|
|
|
await getResponse();
|
2020-02-03 20:08:57 +00:00
|
|
|
await getResponse2();
|
2018-07-12 21:52:06 +00:00
|
|
|
});
|
2018-07-12 19:32:20 +00:00
|
|
|
});
|
|
|
|
|
2018-07-12 21:52:06 +00:00
|
|
|
tap.start({
|
|
|
|
throwOnError: true
|
|
|
|
});
|