From 0e12d7681543e86d2f98f9180a49f372fd26c447 Mon Sep 17 00:00:00 2001 From: Abram Simon Date: Thu, 1 Oct 2020 18:12:14 -0400 Subject: [PATCH] tests: added data file and test coverage to demonstrate encodings The library uses fs.createReadStream to read files when fromFile is called and passes through options, including encoding, to the fs call. This is not obvious, resulting in issue #402. I have added a test to demonstrate this capability and a data file encoded in latin1 for use in the test. Issue #402 --- test/data/dataWithLatin1Encoding | 6 ++++++ test/testCSVConverter2.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) create mode 100644 test/data/dataWithLatin1Encoding diff --git a/test/data/dataWithLatin1Encoding b/test/data/dataWithLatin1Encoding new file mode 100644 index 0000000..0d3aa13 --- /dev/null +++ b/test/data/dataWithLatin1Encoding @@ -0,0 +1,6 @@ +Timestamp,Name +1395426422,bébé +1395426422,Jane +1395426422,Mary +1395426422,Anne +1395426422,Hailey \ No newline at end of file diff --git a/test/testCSVConverter2.ts b/test/testCSVConverter2.ts index 91da899..ec37900 100644 --- a/test/testCSVConverter2.ts +++ b/test/testCSVConverter2.ts @@ -79,6 +79,16 @@ describe("testCSVConverter2", function () { }); }); + it("should parse fromFile with encoding option", function (done) { + var csvFile = __dirname + "/data/dataWithLatin1Encoding"; + var conv = new Converter({ + }); + conv.fromFile(csvFile, { encoding: "latin1" }).then(function (json) { + assert.equal(json[0].Name, 'bébé'); + done(); + }); + }); + it("should fromFile should emit error", function (done) { var csvFile = __dirname + "/data/dataWithUnclosedQuotes"; var conv = new Converter({