Browse Source

Added first cut of some tests for using PapaParse as a Node module

pull/172/head
Rob Dupuis 10 years ago
parent
commit
f51c552917
  1. 52
      tests/node-tests.js
  2. 2
      tests/test.js

52
tests/node-tests.js

@ -0,0 +1,52 @@ @@ -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',
'Donec.elementum@orciluctuset.example',
'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',
'posuere.vulputate.lacus@Donecsollicitudin.example',
'2015-01-31T09:19:02-08:00',
'2014-12-17T04:59:18-08:00',
'Aliquam Iaculis Incorporate',
'Phasellus@Quisquetincidunt.example'
]);
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
tests/test.js

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
require('./node-tests.js');
var connect = require('connect');
var serveStatic = require('serve-static');
var open = require('open');

Loading…
Cancel
Save