Skip to content

Commit

Permalink
Added first cut of some tests for using PapaParse as a Node module
Browse files Browse the repository at this point in the history
  • Loading branch information
robd committed Feb 18, 2015
1 parent ec4c72e commit f51c552
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/node-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function() {
"use strict";

var Papa = require("../papaparse.js");

var fs = require('fs');
var assert = require('assert');
var longSampleRawCsv = fs.readFileSync(__dirname + '/long-sample.csv', 'utf8');

function assertLongSampleParsedCorrectly(parsedCsv) {
assert.equal(8, parsedCsv.data.length)
assert.deepEqual(parsedCsv.data[0], [
'Grant',
'Dyer',
'[email protected]',
'2013-11-23T02:30:31-08:00',
'2014-05-31T01:06:56-07:00',
'Magna Ut Associates',
'ljenkins'
])
assert.deepEqual(parsedCsv.data[7], [
'Talon',
'Salinas',
'[email protected]',
'2015-01-31T09:19:02-08:00',
'2014-12-17T04:59:18-08:00',
'Aliquam Iaculis Incorporate',
'[email protected]'
]);
assert.deepEqual(parsedCsv.meta, {
"delimiter":",",
"linebreak":"\n",
"aborted":false,
"truncated":false,
"cursor":1209
});
assert.equal(parsedCsv.errors.length, 0)
}

var synchronouslyParsedCsvShouldBeCorrectlyParsed = function() {
assertLongSampleParsedCorrectly(Papa.parse(longSampleRawCsv));
}();

var asynchronouslyParsedCsvShouldBeCorrectlyParsed = function() {
Papa.parse(longSampleRawCsv, {
complete: function(parsedCsv) {
assertLongSampleParsedCorrectly(parsedCsv);
},
});
}();

})();
2 changes: 2 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('./node-tests.js');

var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');
Expand Down

0 comments on commit f51c552

Please sign in to comment.