Add more test helpers
While working on some tests, I was having a tricky problem in a test suite. Eventually I tracked it down to an interaction between tests. I suspected the test library, but once I tried to make an isolated test case, I realized the test library was working fine. It turns out it was the server’s request cache. The fix is to clear the cache between tests. Not needed for this PR, though I’m adding it to this branch because it conflicts with this change.
This commit is contained in:
parent
5a45003bc3
commit
de18dce94a
|
@ -103,6 +103,12 @@ Cache.prototype = {
|
|||
return 1;
|
||||
}
|
||||
},
|
||||
|
||||
clear: function () {
|
||||
this.cache.clear();
|
||||
this.newest = null;
|
||||
this.oldest = null;
|
||||
}
|
||||
};
|
||||
|
||||
// In bytes.
|
||||
|
|
|
@ -11,7 +11,6 @@ var camp = Camp.start({
|
|||
hostname: bindAddress,
|
||||
secure: secureServer
|
||||
});
|
||||
module.exports = camp;
|
||||
Camp.log.unpipe('warn', 'stderr');
|
||||
var tryUrl = require('url').format({
|
||||
protocol: secureServer ? 'https' : 'http',
|
||||
|
@ -299,6 +298,11 @@ function cache(f) {
|
|||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
camp,
|
||||
requestCache
|
||||
};
|
||||
|
||||
camp.notfound(/\.(svg|png|gif|jpg|json)/, function(query, match, end, request) {
|
||||
var format = match[1];
|
||||
var badgeData = getBadgeData("404", query);
|
||||
|
|
|
@ -137,4 +137,22 @@ describe('The LRU cache', function () {
|
|||
assert.equal(slot2.newer, null);
|
||||
});
|
||||
|
||||
it('should clear', function () {
|
||||
// Set up.
|
||||
const cache = new LRU(2);
|
||||
cache.set('key1', 'value1');
|
||||
cache.set('key2', 'value2');
|
||||
|
||||
// Confidence check.
|
||||
assert.equal(cache.get('key1'), 'value1');
|
||||
assert.equal(cache.get('key2'), 'value2');
|
||||
|
||||
// Run.
|
||||
cache.clear();
|
||||
|
||||
// Test.
|
||||
assert.equal(cache.get('key1'), null);
|
||||
assert.equal(cache.get('key2'), null);
|
||||
assert.equal(cache.cache.size, 0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -79,7 +79,7 @@ describe('The server', function () {
|
|||
server = require('../server');
|
||||
});
|
||||
after('Shut down the server', function(done) {
|
||||
server.close(function () { done(); });
|
||||
server.camp.close(function () { done(); });
|
||||
});
|
||||
|
||||
it('should produce colorscheme badges', function(done) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user