Skip to content

Commit

Permalink
tests: added data file and test coverage to demonstrate encodings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
abramsimon committed Oct 1, 2020
1 parent 4fcda10 commit 0e12d76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/data/dataWithLatin1Encoding
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Timestamp,Name
1395426422,b�b�
1395426422,Jane
1395426422,Mary
1395426422,Anne
1395426422,Hailey
10 changes: 10 additions & 0 deletions test/testCSVConverter2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 0e12d76

Please sign in to comment.