Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

port coarse UA parser tests to vows

  • Loading branch information...
commit dda7622dad061e3ffbdb90c581037dab297453a8 1 parent ef7818e
@lloyd lloyd authored
Showing with 27 additions and 19 deletions.
  1. +27 −19 tests/coarse-user-agent-parser-test.js
View
46 tests/coarse-user-agent-parser-test.js 100644 → 100755
@@ -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);
}
-});
+});
+
+// run or export the suite.
+if (process.argv[1] === __filename) suite.run();
+else suite.export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.