Skip to content

Commit

Permalink
Use lolex for faking date in tests (#491)
Browse files Browse the repository at this point in the history
Sinon.JS provides a project called lolex to handle faking dates. This
change replaces the fakeDate utility with the equivalent Sinon.JS code.
  • Loading branch information
MitMaro authored and ziluvatar committed Jun 16, 2018
1 parent 9676a83 commit 677ead6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "JSON Web Token implementation (symmetric and asymmetric)",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text mocha --require test/util/fakeDate && nsp check && cost-of-modules"
"test": "nyc --reporter=html --reporter=text mocha && nsp check && cost-of-modules"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,7 +37,7 @@
"mocha": "^2.1.0",
"nsp": "^2.6.2",
"nyc": "^11.8.0",
"sinon": "^1.15.4"
"sinon": "^6.0.0"
},
"engines": {
"npm": ">=1.4.28",
Expand Down
5 changes: 3 additions & 2 deletions test/jwt.asymmetric_signing.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path');
var expect = require('chai').expect;
var assert = require('chai').assert;
var ms = require('ms');
var sinon = require('sinon');

function loadKey(filename) {
return fs.readFileSync(path.join(__dirname, filename));
Expand Down Expand Up @@ -140,14 +141,14 @@ describe('Asymmetric Algorithms', function(){


it('should valid when date are equals', function (done) {
Date.fix(1451908031);
var fakeClock = sinon.useFakeTimers({now: 1451908031});

token = jwt.sign({ foo: 'bar' }, priv, { algorithm: algorithm, notBefore: 0 });

jwt.verify(token, pub, function (err, decoded) {
fakeClock.uninstall();
assert.isNull(err);
assert.isNotNull(decoded);
Date.unfix();
done();
});
});
Expand Down
32 changes: 0 additions & 32 deletions test/util/fakeDate.js

This file was deleted.

0 comments on commit 677ead6

Please sign in to comment.