version-service
Advanced tools
Comparing version
@@ -32,2 +32,5 @@ 'use strict'; | ||
_createClass(Version, [{ | ||
key: 'stop', | ||
value: function stop() {} | ||
}, { | ||
key: 'getVersion', | ||
@@ -70,3 +73,3 @@ value: function getVersion() { | ||
var timeouId = setTimeout(function () { | ||
var timeoutId = setTimeout(function () { | ||
_this2.checkVersion().then(function (version) { | ||
@@ -84,6 +87,4 @@ if (version.isCurrent) { | ||
}, this._timeout); | ||
return { | ||
cancel: function cancel() { | ||
clearTimeout(timeouId); | ||
} | ||
this.stop = function () { | ||
clearTimeout(timeoutId); | ||
}; | ||
@@ -90,0 +91,0 @@ } |
{ | ||
"name": "version-service", | ||
"version": "1.1.2", | ||
"version": "1.2.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./build/version.js", |
@@ -13,3 +13,2 @@ # Version Service | ||
## Use | ||
```js | ||
@@ -35,2 +34,8 @@ var Version = require('version-service'); | ||
}); | ||
// to run periodic checks | ||
versionService.start(); | ||
// to cancel the periodic checks | ||
versionService.stop(); | ||
``` |
@@ -12,2 +12,6 @@ import Promise from 'es6-promise'; | ||
stop() { | ||
} | ||
get url() { | ||
@@ -69,3 +73,3 @@ return this._url; | ||
start() { | ||
var timeouId = setTimeout(() => { | ||
var timeoutId = setTimeout(() => { | ||
this.checkVersion().then((version) => { | ||
@@ -83,8 +87,7 @@ if(version.isCurrent) { | ||
}, this._timeout) | ||
return { | ||
cancel: function() { | ||
clearTimeout(timeouId); | ||
} | ||
} | ||
this.stop = function() { | ||
clearTimeout(timeoutId); | ||
}; | ||
} | ||
} |
@@ -65,5 +65,5 @@ import {expect} from 'chai'; | ||
it('should check version over an interval', () => { | ||
it('should periodically check version over an interval', (done) => { | ||
const url = 'http://localhost:3000/version.json'; | ||
const timeout = 100; | ||
const timeout = 5; | ||
const callback = function(localVersion, responseVersion) { | ||
@@ -94,2 +94,32 @@ expect(localVersion).to.not.equal(responseVersion); | ||
it('should cancel periodic check', () => { | ||
const url = 'http://localhost:3000/version.json'; | ||
const timeout = 5; | ||
var test_bool = true; | ||
const callback = function(localVersion, responseVersion) { | ||
test_bool = false; | ||
}; | ||
const versionNumber = '1.0.0' | ||
const myVersion = new Version(url, versionNumber, timeout, callback); | ||
const versionRequest = nock('http://localhost:3000') | ||
.get('/version.json') | ||
.times(4) | ||
.reply(200, { | ||
status: 'success', | ||
data: { | ||
version: '1.0.0' | ||
} | ||
}) | ||
.get('/version.json') | ||
.reply(200, { | ||
status: 'success', | ||
data: { | ||
version: '1.0.1' | ||
} | ||
}); | ||
myVersion.start(); | ||
myVersion.stop(); | ||
expect(test_bool).to.equal(true); | ||
}); | ||
}); |
10311
9.59%295
11.32%39
14.71%