From f51c5529179a31a2ca6a255b076ec19791f8c0a4 Mon Sep 17 00:00:00 2001 From: Rob Dupuis Date: Wed, 18 Feb 2015 21:03:42 +0000 Subject: [PATCH] Added first cut of some tests for using PapaParse as a Node module --- tests/node-tests.js | 52 +++++++++++++++++++++++++++++++++++++++++++++ tests/test.js | 2 ++ 2 files changed, 54 insertions(+) create mode 100644 tests/node-tests.js diff --git a/tests/node-tests.js b/tests/node-tests.js new file mode 100644 index 0000000..b6a3041 --- /dev/null +++ b/tests/node-tests.js @@ -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); + }, + }); + }(); + +})(); \ No newline at end of file diff --git a/tests/test.js b/tests/test.js index 4961d4f..0a5e6a6 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,3 +1,5 @@ +require('./node-tests.js'); + var connect = require('connect'); var serveStatic = require('serve-static'); var open = require('open');