-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
|
||
var test = require('test-runner'); | ||
var UsageStats = require('../lib/usage-stats'); | ||
var a = require('core-assert'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var os = require('os'); | ||
var rimraf = require('rimraf'); | ||
|
||
var tmpPath = path.resolve(__dirname, '../../tmp/test'); | ||
function getCacheDir(index) { | ||
var dir = path.resolve(tmpPath, 'test' + index); | ||
rimraf.sync(dir); | ||
return dir; | ||
} | ||
|
||
try { | ||
fs.mkdirSync(tmpPath); | ||
} catch (err) {} | ||
|
||
test('.send({ debug: true }) - screenview', function () { | ||
var testStats = new UsageStats('UA-70853320-3', { | ||
name: 'usage-stats', | ||
version: require('../../package').version, | ||
dir: getCacheDir(this.index) | ||
}); | ||
|
||
testStats.screenView(this.name); | ||
return testStats.send({ debug: true }).then(function (response) { | ||
a.strictEqual(response.hits.length, 1); | ||
a.ok(/t=screenview/.test(response.hits[0])); | ||
a.strictEqual(response.result.hitParsingResult[0].valid, true); | ||
var queued = testStats._dequeue(); | ||
a.strictEqual(queued.length, 1); | ||
}); | ||
}); | ||
|
||
test('.send({ debug: true }) - screenview with a queue', function () { | ||
var testStats = new UsageStats('UA-70853320-3', { | ||
name: 'usage-stats', | ||
version: require('../../package').version, | ||
dir: getCacheDir(this.index) | ||
}); | ||
testStats._enqueue(['v=1']); | ||
testStats.screenView(this.name); | ||
return testStats.send({ debug: true }).then(function (response) { | ||
a.strictEqual(response.hits.length, 2); | ||
a.ok(/t=screenview/.test(response.hits[1])); | ||
a.strictEqual(response.result.hitParsingResult[1].valid, true); | ||
var queued = testStats._dequeue(); | ||
|
||
a.strictEqual(queued.length, 2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict' | ||
const test = require('test-runner') | ||
const UsageStats = require('../lib/usage-stats') | ||
const a = require('core-assert') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const os = require('os') | ||
const rimraf = require('rimraf') | ||
|
||
const tmpPath = path.resolve(__dirname, '../../tmp/test') | ||
function getCacheDir (index) { | ||
const dir = path.resolve(tmpPath, 'test' + index) | ||
rimraf.sync(dir) | ||
return dir | ||
} | ||
|
||
try { | ||
fs.mkdirSync(tmpPath) | ||
} catch (err) { | ||
// exists | ||
} | ||
|
||
test('.send({ debug: true }) - screenview', function () { | ||
const testStats = new UsageStats('UA-70853320-3', { | ||
name: 'usage-stats', | ||
version: require('../../package').version, | ||
dir: getCacheDir(this.index) | ||
}) | ||
|
||
testStats.screenView(this.name) | ||
return testStats.send({ debug: true }) | ||
.then(response => { | ||
a.strictEqual(response.hits.length, 1) | ||
a.ok(/t=screenview/.test(response.hits[0])) | ||
a.strictEqual(response.result.hitParsingResult[0].valid, true) | ||
const queued = testStats._dequeue() | ||
a.strictEqual(queued.length, 1) | ||
}) | ||
}) | ||
|
||
test('.send({ debug: true }) - screenview with a queue', function () { | ||
const testStats = new UsageStats('UA-70853320-3', { | ||
name: 'usage-stats', | ||
version: require('../../package').version, | ||
dir: getCacheDir(this.index) | ||
}) | ||
testStats._enqueue([ 'v=1' ]) | ||
testStats.screenView(this.name) | ||
return testStats.send({ debug: true }) | ||
.then(response => { | ||
// console.error(require('util').inspect(response, { depth: 3, colors: true })) | ||
a.strictEqual(response.hits.length, 2) | ||
a.ok(/t=screenview/.test(response.hits[1])) | ||
a.strictEqual(response.result.hitParsingResult[1].valid, true) | ||
const queued = testStats._dequeue() | ||
// console.error(queued) | ||
a.strictEqual(queued.length, 2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters