app-usage-stats
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -49,6 +49,7 @@ 'use strict'; | ||
if (this._disabled) return Promise.resolve([]); | ||
options = options || {}; | ||
this.unsent.add({ dimension: dimension, metric: metric }); | ||
if (this.sendInterval) { | ||
if (Date.now() - this._lastSent >= this.sendInterval) { | ||
if (Date.now() - this._lastSent >= this.sendInterval || options.send) { | ||
return this.send(options); | ||
@@ -55,0 +56,0 @@ } else { |
@@ -145,2 +145,9 @@ 'use strict'; | ||
runner.test('.hit({ send: true }): override auto-send interval', function () { | ||
var usage = new TrackUsage(tid, { sendInterval: 20000, dir: 'tmp/test' }); | ||
return usage.hit({ name: 'one' }, { metric: 1 }, { send: true }).then(responseCount(1)).then(unsentCount(usage, 0)).then(sentCount(usage, 1)).then(function () { | ||
return usage.hit({ name: 'two' }, { metric: 1 }, { send: true }).then(responseCount(1)).then(unsentCount(usage, 0)).then(sentCount(usage, 2)); | ||
}); | ||
}); | ||
runner.test('.send(): this.stats correct after', function () { | ||
@@ -172,3 +179,5 @@ var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var prom = usage.send().then(responseCount(1)).then(unsentCount(usage, 3)).then(sentCount(usage, 1)); | ||
var prom = usage.send().then(responseCount(1)).then(unsentCount(usage, 3)).then(sentCount(usage, 1)).then(function () { | ||
return usage.send().then(responseCount(1)).then(unsentCount(usage, 0)).then(sentCount(usage, 4)); | ||
}); | ||
@@ -181,7 +190,5 @@ unsentCount(usage, 0)(); | ||
var prom2 = delay(3000).then(usage.send.bind(usage)).then(responseCount(1)).then(unsentCount(usage, 0)).then(sentCount(usage, 4)); | ||
return Promise.all([prom, prom2]); | ||
return prom; | ||
}); | ||
runner.test('.hit() validation: all metrics are numeric', function () {}); | ||
runner.test('.hit() validation: all metrics are numeric'); |
{ | ||
"name": "app-usage-stats", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "A convention for tracking javascript application usage", | ||
@@ -6,0 +6,0 @@ "repository": "https://github.com/75lb/app-usage-stats.git", |
@@ -65,5 +65,7 @@ 'use strict' | ||
* @param [options.timeout] {number} - A maxium wait period in ms, after which any pending requests will be aborted. | ||
* @param [options.send] {number} - Each hit will be sent. | ||
*/ | ||
hit (dimension, metric, options) { | ||
if (this._disabled) return Promise.resolve([]) | ||
options = options || {} | ||
this.unsent.add({ dimension, metric }) | ||
@@ -73,3 +75,3 @@ | ||
if (this.sendInterval) { | ||
if (Date.now() - this._lastSent >= this.sendInterval) { | ||
if (Date.now() - this._lastSent >= this.sendInterval || options.send) { | ||
return this.send(options) | ||
@@ -76,0 +78,0 @@ } else { |
@@ -172,2 +172,16 @@ 'use strict' | ||
runner.test('.hit({ send: true }): override auto-send interval', function () { | ||
const usage = new TrackUsage(tid, { sendInterval: 20000, dir: 'tmp/test' }) | ||
return usage.hit({ name: 'one' }, { metric: 1 }, { send: true }) | ||
.then(responseCount(1)) | ||
.then(unsentCount(usage, 0)) | ||
.then(sentCount(usage, 1)) | ||
.then(() => { | ||
return usage.hit({ name: 'two' }, { metric: 1 }, { send: true }) | ||
.then(responseCount(1)) | ||
.then(unsentCount(usage, 0)) | ||
.then(sentCount(usage, 2)) | ||
}) | ||
}) | ||
runner.test('.send(): this.stats correct after', function () { | ||
@@ -209,2 +223,8 @@ const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
.then(sentCount(usage, 1)) | ||
.then(() => { | ||
return usage.send() | ||
.then(responseCount(1)) | ||
.then(unsentCount(usage, 0)) | ||
.then(sentCount(usage, 4)) | ||
}) | ||
@@ -217,13 +237,5 @@ unsentCount(usage, 0)() | ||
const prom2 = delay(3000) | ||
.then(usage.send.bind(usage)) | ||
.then(responseCount(1)) | ||
.then(unsentCount(usage, 0)) | ||
.then(sentCount(usage, 4)) | ||
return Promise.all([ prom, prom2 ]) | ||
return prom | ||
}) | ||
runner.test('.hit() validation: all metrics are numeric', function () { | ||
}) | ||
runner.test('.hit() validation: all metrics are numeric') |
@@ -1,1 +0,1 @@ | ||
1475360856626 | ||
1475396443387 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54318
1326