Skip to content

Commit

Permalink
Updating mocha and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpodwys committed Feb 16, 2019
1 parent c69fd9d commit 5ae6ab9
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 88 deletions.
7 changes: 5 additions & 2 deletions cacheModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function cacheModule(config){
refreshKeys: {}
};
var storageKey;
var interval;

setupBrowserStorage();
log(false, 'Cache-module client created with the following defaults:', {type: self.type, defaultExpiration: self.defaultExpiration, verbose: self.verbose, readOnly: self.readOnly});
Expand Down Expand Up @@ -164,7 +165,7 @@ function cacheModule(config){
delete cache.db[keys];
delete cache.expirations[keys];
delete cache.refreshKeys[keys];
if(cb) cb(null, 1);
if(cb) cb(null, 1);
}
overwriteBrowserStorage();
}
Expand All @@ -180,6 +181,8 @@ function cacheModule(config){
cache.refreshKeys = {};
if(cb) cb();
overwriteBrowserStorage();
if(interval) clearInterval(interval);
backgroundRefreshEnabled = false;
}

/**
Expand Down Expand Up @@ -252,7 +255,7 @@ function cacheModule(config){
throw new Error('BACKGROUND_REFRESH_INTERVAL_EXCEPTION: backgroundRefreshInterval cannot be greater than backgroundRefreshMinTtl.');
}
}
setInterval(backgroundRefresh, self.backgroundRefreshInterval);
interval = setInterval(backgroundRefresh, self.backgroundRefreshInterval);
}
}

Expand Down
210 changes: 126 additions & 84 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A cache plugin for cache-service.",
"main": "cacheModule.js",
"devDependencies": {
"mocha": "2.2.4",
"expect": "1.6.0",
"mocha": "^5.2.0",
"mock-localstorage": "0.1.3"
},
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion test/server/cache-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ beforeEach(function(){
cacheModule.flush();
});

after(function(){
cacheModule.flush();
});

describe('cacheModule Tests', function () {
it('Getting absent key should return null', function (done) {
cacheModule.get(key, function (err, result){
Expand Down Expand Up @@ -92,7 +96,7 @@ describe('cacheModule Tests', function () {
var refresh = function(key, cb){
cb(null, 1);
}
cacheModule.set(key, value, 1, refresh, function (err, result){
cacheModule.set(key, value, 1, refresh, function (err, result){
setTimeout(function(){
cacheModule.get(key, function (err, response){
expect(response).toBe(1);
Expand Down

0 comments on commit 5ae6ab9

Please sign in to comment.