app-usage-stats
Advanced tools
Comparing version 0.3.4 to 0.3.5
@@ -9,2 +9,3 @@ 'use strict'; | ||
var mkdirp = require('mkdirp'); | ||
var path = require('path'); | ||
@@ -115,3 +116,5 @@ var runner = new TestRunner(); | ||
runner.test('.save() and .load(): this.stats correct', function () { | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var _this = this; | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' + this.index }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -121,3 +124,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
return usage.save().then(unsentCount(usage, 0)).then(sentCount(usage, 0)).then(function () { | ||
fs.readFileSync('tmp/test/UA-70853320-4-unsent.json'); | ||
fs.readFileSync('tmp/test' + _this.index + '/UA-70853320-4-unsent.json'); | ||
return usage.load().then(function () { | ||
@@ -130,3 +133,3 @@ a.deepStrictEqual(usage.unsent.stats, [{ dimension: { name: 'one' }, metric: { metric: 2 } }]); | ||
runner.test('.saveSync() and .loadSync(): this.stats correct', function () { | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' + this.index }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -137,3 +140,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
a.deepStrictEqual(usage.unsent.stats, []); | ||
fs.readFileSync('tmp/test/UA-70853320-4-unsent.json'); | ||
fs.readFileSync('tmp/test' + this.index + '/UA-70853320-4-unsent.json'); | ||
usage.loadSync(); | ||
@@ -144,3 +147,3 @@ a.deepStrictEqual(usage.unsent.stats, [{ dimension: { name: 'one' }, metric: { metric: 2 } }]); | ||
runner.test('.hit(): auto-sends after given interval', function () { | ||
var usage = new TrackUsage(tid, { sendInterval: 200, dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { sendInterval: 200, dir: 'tmp/test' + this.index }); | ||
return Promise.all([usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), delay(210).then(unsentCount(usage, 1)).then(function () { | ||
@@ -152,3 +155,3 @@ return usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(1)).then(sentCount(usage, 1)).then(unsentCount(usage, 0)); | ||
runner.test('.hit({ send: true }): override auto-send interval', function () { | ||
var usage = new TrackUsage(tid, { sendInterval: 20000, dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { sendInterval: 20000, dir: 'tmp/test' + this.index }); | ||
return usage.hit({ name: 'one' }, { metric: 1 }, { send: true }).then(responseCount(1)).then(unsentCount(usage, 0)).then(sentCount(usage, 1)).then(function () { | ||
@@ -160,3 +163,3 @@ 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 () { | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' + this.index }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -169,3 +172,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.send(): this.stats correct after ongoing hits', function () { | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' + this.index }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -182,3 +185,3 @@ usage.hit({ name: 'one' }, { metric: 1 }); | ||
runner.test('.send(): multiple invocations', function () { | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' }); | ||
var usage = new TrackUsage(tid, { dir: 'tmp/test' + this.index }); | ||
usage.hit({ name: 'one' }, { metric: 1 }); | ||
@@ -185,0 +188,0 @@ usage.hit({ name: 'one' }, { metric: 1 }); |
'use strict' | ||
var detect = require('feature-detect-es6') | ||
if (!Array.prototype.includes) require('core-js/es7/array') | ||
if (detect.all('class', 'arrowFunction', 'let', 'const', 'destructuring')) { | ||
@@ -5,0 +7,0 @@ module.exports = require('./src/lib/app-usage-stats') |
{ | ||
"name": "app-usage-stats", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "A convention for tracking javascript application usage", | ||
@@ -20,2 +20,3 @@ "repository": "https://github.com/75lb/app-usage-stats.git", | ||
"array-back": "^1.0.3", | ||
"core-js": "^2.4.1", | ||
"feature-detect-es6": "^1.3.1", | ||
@@ -27,3 +28,3 @@ "home-path": "^1.0.3", | ||
"devDependencies": { | ||
"core-assert": "^0.2.0", | ||
"core-assert": "^0.2.1", | ||
"babel-preset-es2015": "^6.16.0", | ||
@@ -30,0 +31,0 @@ "mkdirp": "^0.5.1", |
@@ -15,7 +15,7 @@ [![view on npm](http://img.shields.io/npm/v/app-usage-stats.svg)](https://www.npmjs.org/package/app-usage-stats) | ||
const UsageStats = require('app-usage-stats') | ||
const stats = new UsageStats('UA-987654321', 'app-name') | ||
const stats = new UsageStats('UA-987654321') | ||
``` | ||
* [app-usage-stats](#module_app-usage-stats) | ||
* [AppUsageStats](#exp_module_app-usage-stats--AppUsageStats) ⏏ | ||
* [AppUsageStats](#exp_module_app-usage-stats--AppUsageStats) ⇐ <code>[UsageStats](https://github.com/75lb/usage-stats)</code> ⏏ | ||
* [new AppUsageStats(tid, [options])](#new_module_app-usage-stats--AppUsageStats_new) | ||
@@ -34,4 +34,5 @@ * [.unsent](#module_app-usage-stats--AppUsageStats.AppUsageStats+unsent) : <code>Array.<object></code> | ||
### AppUsageStats ⏏ | ||
### AppUsageStats ⇐ <code>[UsageStats](https://github.com/75lb/usage-stats)</code> ⏏ | ||
**Kind**: Exported class | ||
**Extends:** <code>[UsageStats](https://github.com/75lb/usage-stats)</code> | ||
<a name="new_module_app-usage-stats--AppUsageStats_new"></a> | ||
@@ -51,3 +52,3 @@ | ||
#### stats.unsent : <code>Array.<object></code> | ||
#### usage.unsent : <code>Array.<object></code> | ||
Current totals not yet sent | ||
@@ -58,3 +59,3 @@ | ||
#### stats.sent : <code>Array.<object></code> | ||
#### usage.sent : <code>Array.<object></code> | ||
Current totals not yet sent | ||
@@ -65,3 +66,3 @@ | ||
#### stats.queuePath : <code>string</code> | ||
#### usage.queuePath : <code>string</code> | ||
Queued stats path | ||
@@ -72,3 +73,3 @@ | ||
#### stats.hit(dimension, metric, [options]) | ||
#### usage.hit(dimension, metric, [options]) | ||
Track a hit. The magic dimension `name` will be mapped to a GA screenView. | ||
@@ -84,6 +85,7 @@ | ||
| [options.timeout] | <code>number</code> | A maxium wait period in ms, after which any pending requests will be aborted. | | ||
| [options.send] | <code>number</code> | Each hit will be sent. | | ||
<a name="module_app-usage-stats--AppUsageStats+save"></a> | ||
#### stats.save() | ||
#### usage.save() | ||
Save stats | ||
@@ -94,3 +96,3 @@ | ||
#### stats.saveSync() | ||
#### usage.saveSync() | ||
Save stats sync. | ||
@@ -101,3 +103,3 @@ | ||
#### stats.load() | ||
#### usage.load() | ||
Load stats | ||
@@ -108,3 +110,3 @@ | ||
#### stats.loadSync() | ||
#### usage.loadSync() | ||
Loads stats sync. | ||
@@ -115,3 +117,3 @@ | ||
#### stats.send([options]) | ||
#### usage.send([options]) | ||
Send and reset stats. | ||
@@ -118,0 +120,0 @@ |
@@ -12,3 +12,3 @@ 'use strict' | ||
* const UsageStats = require('app-usage-stats') | ||
* const stats = new UsageStats('UA-987654321', 'app-name') | ||
* const stats = new UsageStats('UA-987654321') | ||
*/ | ||
@@ -18,3 +18,4 @@ | ||
* @alias module:app-usage-stats | ||
* @typicalname stats | ||
* @typicalname usage | ||
* @extends {external:UsageStats} | ||
*/ | ||
@@ -206,1 +207,6 @@ class AppUsageStats extends UsageStats { | ||
module.exports = AppUsageStats | ||
/** | ||
* @external UsageStats | ||
* @see https://github.com/75lb/usage-stats | ||
*/ |
@@ -8,2 +8,3 @@ 'use strict' | ||
const mkdirp = require('mkdirp') | ||
const path = require('path') | ||
@@ -118,3 +119,3 @@ const runner = new TestRunner() | ||
runner.test('.save() and .load(): this.stats correct', function () { | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: `tmp/test${this.index}` }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -129,3 +130,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
.then(() => { | ||
fs.readFileSync('tmp/test/UA-70853320-4-unsent.json') | ||
fs.readFileSync(`tmp/test${this.index}/UA-70853320-4-unsent.json`) | ||
return usage.load() | ||
@@ -141,3 +142,3 @@ .then(() => { | ||
runner.test('.saveSync() and .loadSync(): this.stats correct', function () { | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: `tmp/test${this.index}` }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -150,3 +151,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
a.deepStrictEqual(usage.unsent.stats, []) | ||
fs.readFileSync('tmp/test/UA-70853320-4-unsent.json') | ||
fs.readFileSync(`tmp/test${this.index}/UA-70853320-4-unsent.json`) | ||
usage.loadSync() | ||
@@ -159,3 +160,3 @@ a.deepStrictEqual(usage.unsent.stats, [ | ||
runner.test('.hit(): auto-sends after given interval', function () { | ||
const usage = new TrackUsage(tid, { sendInterval: 200, dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { sendInterval: 200, dir: `tmp/test${this.index}` }) | ||
return Promise.all([ | ||
@@ -177,3 +178,3 @@ usage.hit({ name: 'one' }, { metric: 1 }).then(responseCount(0)), | ||
runner.test('.hit({ send: true }): override auto-send interval', function () { | ||
const usage = new TrackUsage(tid, { sendInterval: 20000, dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { sendInterval: 20000, dir: `tmp/test${this.index}` }) | ||
return usage.hit({ name: 'one' }, { metric: 1 }, { send: true }) | ||
@@ -192,3 +193,3 @@ .then(responseCount(1)) | ||
runner.test('.send(): this.stats correct after', function () { | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: `tmp/test${this.index}` }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -204,3 +205,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.send(): this.stats correct after ongoing hits', function () { | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: `tmp/test${this.index}` }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -220,3 +221,3 @@ usage.hit({ name: 'one' }, { metric: 1 }) | ||
runner.test('.send(): multiple invocations', function () { | ||
const usage = new TrackUsage(tid, { dir: 'tmp/test' }) | ||
const usage = new TrackUsage(tid, { dir: `tmp/test${this.index}` }) | ||
usage.hit({ name: 'one' }, { metric: 1 }) | ||
@@ -223,0 +224,0 @@ usage.hit({ name: 'one' }, { metric: 1 }) |
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
52754
35
1218
121
6
+ Addedcore-js@^2.4.1