Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[tests]

  • Loading branch information...
commit cba75b17f1e02680d9342284be5492549882bec8 1 parent 2e7e51b
@3rd-Eden authored
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
3  .travis.yml
@@ -0,0 +1,3 @@
+language: node_js
+node_js:
+ - 0.8
View
14 Makefile
@@ -0,0 +1,14 @@
+# configuration for the test suite
+ALL_TESTS = $(shell find tests/ -name '*.test.js')
+REPORTER = spec
+UI = exports
+
+test:
+ @./node_modules/.bin/mocha \
+ --reporter $(REPORTER) \
+ --timeout 4000 \
+ --ui $(UI) \
+ --growl \
+ $(ALL_TESTS)
+
+.PHONY: test
View
2  index.js
@@ -75,7 +75,7 @@ Expire.prototype.set = function set(key, value, expires) {
Expire.prototype.has = function has(key) {
var now = Date.now();
- return key in this.cache && (now - this.cache[key].last) >= this.cache[key].expires;
+ return key in this.cache && (now - this.cache[key].last) <= this.cache[key].expires;
};
/**
View
6 package.json
@@ -24,5 +24,9 @@
"expiree"
],
"author": "Arnout Kazemier",
- "license": "MIT"
+ "license": "MIT",
+ "devDependencies": {
+ "mocha": "1.4.x",
+ "chai": "1.2.x"
+ }
}
View
93 tests/expirable.test.js
@@ -0,0 +1,93 @@
+'use strict';
+
+// set up chai, our assertation library
+var chai = require('chai')
+ , expect = chai.expect;
+
+chai.Assertion.includeStack = true;
+
+describe('Expirable', function () {
+ var Expirable = require('../');
+
+ it('should just work without arguments', function () {
+ var cache = new Expirable();
+
+ cache.destroy();
+ });
+
+ it('should set the expiree as first argument', function () {
+ var cache = new Expirable('5 seconds');
+
+ cache.destroy();
+ });
+
+ it('should get and get the value', function () {
+ var cache = new Expirable('5 minutes');
+
+ cache.set('foo', 'bar');
+ expect(cache.get('foo')).to.equal('bar');
+
+ cache.destroy();
+ });
+
+ it('should have the key after setting', function () {
+ var cache = new Expirable('1 second');
+
+ cache.set('foo', 'bar');
+ expect(cache.has('foo')).to.equal(true);
+
+ cache.destroy();
+ });
+
+ it('should expire the cache', function (done) {
+ var cache = new Expirable('5ms');
+
+ cache.set('foo', 'bar');
+
+ setTimeout(function () {
+ expect(cache.has('foo')).to.equal(false);
+ expect(cache.get('foo')).to.equal(undefined);
+
+ cache.destroy();
+ done();
+ }, 10);
+ });
+
+ it('should remove keys', function () {
+ var cache = new Expirable('10000 ms');
+
+ cache.set('foo', 'bar');
+ cache.remove('foo');
+ expect(cache.get('foo')).to.equal(undefined);
+
+ cache.destroy();
+ });
+
+ it('should override default expire time during set', function (done) {
+ var cache = new Expirable('5 ms');
+
+ cache.set('foo', 'bar', '10 minutes');
+
+ setTimeout(function () {
+ expect(cache.get('foo')).to.equal('bar');
+
+ cache.destroy();
+ done();
+ }, 20);
+ });
+
+ it('should stop the scan, but still.. kill item when we get it', function (done) {
+ var cache = new Expirable('15 ms');
+
+ cache.set('foo', 'trololol');
+ cache.stop();
+
+ setTimeout(function () {
+ expect(cache.cache.foo.value).to.equal('trololol');
+ expect(cache.get('foo')).to.equal(undefined);
+
+ cache.destroy();
+ done();
+ }, 50);
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.