Skip to content

Commit

Permalink
Breaking: Avoid returning 0, return 1 if millisecond resolution (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 11, 2016
1 parent 14b6c36 commit 0059b0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Split out for standalone use.
var defaultResolution = require('default-resolution');

defaultResolution();
//-> 1000 in node 0.10
//-> 0 in node 0.11+
//-> 1000 (1 second) in node 0.10
//-> 1 (millisecond) in node 0.11+

// use a different value
defaultResolution(12);
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
var nodeVersion = require('./node-version');

function defaultResolution(customResolution) {
var resolution = parseInt(customResolution, 10) || 0;
var resolution = parseInt(customResolution, 10);

if (resolution) {
return resolution;
}

return (nodeVersion.major === 0 && nodeVersion.minor <= 10) ? 1000 : 0;
return (nodeVersion.major === 0 && nodeVersion.minor <= 10) ? 1000 : 1;
}

defaultResolution.nodeVersion = nodeVersion;
Expand Down
14 changes: 7 additions & 7 deletions test/default-resolution.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ lab.describe('defaultResolution', function() {
done();
});

lab.it('should return default resolution to 1000 on node v0.10', function(done) {
lab.it('should return default resolution to 1000 (1 second) on node v0.10', function(done) {
nodeVersion.major = 0;
nodeVersion.minor = 10;
code.expect(defaultResolution()).to.equal(1000);
done();
});

lab.it('should return default resolution to 0 on node v0.11', function(done) {
lab.it('should return default resolution to 1 (millisecond) on node v0.11', function(done) {
nodeVersion.major = 0;
nodeVersion.minor = 11;
code.expect(defaultResolution()).to.equal(0);
code.expect(defaultResolution()).to.equal(1);
done();
});

lab.it('should return default resolution to 0 on node v0.12', function(done) {
lab.it('should return default resolution to 1 (millisecond) on node v0.12', function(done) {
nodeVersion.major = 0;
nodeVersion.minor = 12;
code.expect(defaultResolution()).to.equal(0);
code.expect(defaultResolution()).to.equal(1);
done();
});

lab.it('should return default resolution to 0 on iojs v1.5', function(done) {
lab.it('should return default resolution to 1 (millisecond) on iojs v1.5', function(done) {
nodeVersion.major = 1;
nodeVersion.minor = 1;
code.expect(defaultResolution()).to.equal(0);
code.expect(defaultResolution()).to.equal(1);
done();
});

Expand Down

0 comments on commit 0059b0b

Please sign in to comment.