Skip to content
Snippets Groups Projects
Commit ccafa86c authored by Austin King's avatar Austin King
Browse files

Merge branch 'kpi-backend' of github.com:mozilla/browserid into kpi-backend

parents ac25f0ca dda7622d
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ const fs = require('fs'),
// TODO: convert to vows based test (or introduce nodeunit dependency)
vows = require('vows'),
coarse = require('../lib/coarse_user_agent_parser'),
assert = require('assert'),
path = require('path');
var suite = vows.describe('coarse-user-agent-parser');
......@@ -17,26 +18,33 @@ suite.options.error = false;
/* Update test data with https://gist.github.com/2590547 */
fs.readFile(path.join(__dirname, 'data/user_agents.json'), 'utf-8', function (err, data) {
if (err) {
console.error(err);
} else {
var test_data = JSON.parse(data);
for (var i=0; i < test_data.tests.length; i++) {
var t = test_data.tests[i];
if (t.ua) {
var actual = coarse.parse(t.ua);
if (actual.os != t.os) {
console.error('Error parsing ' + t.ua + ' expected [' + t.os + '] got [' + actual.os + ']');
}
if (actual.browser != t.browser) {
console.error('Error parsing ' + t.ua + ' expected [' + t.browser + '] got [' + actual.browser + ']');
}
if (actual.version != t.version) {
console.error('Error parsing ' + t.ua + ' expected [' + t.version + '] got [' + actual.version + ']');
suite.addBatch({
"UA parsing": {
topic: function() {
fs.readFile(path.join(__dirname, 'data/user_agents.json'), 'utf-8', this.callback);
},
"data can be read": function(err, data) {
assert.isNull(err);
},
"with lots of data": {
topic: function(err, data) {
this.callback(JSON.parse(data));
},
"demonstrates proper functioning of coarse parser": function(test_data) {
for (var i=0; i < test_data.tests.length; i++) {
var t = test_data.tests[i];
if (t.ua) {
var actual = coarse.parse(t.ua);
assert.strictEqual(t.os, actual.os, t.ua);
assert.strictEqual(t.browser, actual.browser, t.ua);
assert.strictEqual(t.version, actual.version, t.ua);
}
}
}
}
console.log('Finished ' + test_data.tests.length);
}
});
\ No newline at end of file
});
// run or export the suite.
if (process.argv[1] === __filename) suite.run();
else suite.export(module);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment