Skip to content

Commit 0e12d76

Browse files
committed
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
1 parent 4fcda10 commit 0e12d76

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

test/data/dataWithLatin1Encoding

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Timestamp,Name
2+
1395426422,b�b�
3+
1395426422,Jane
4+
1395426422,Mary
5+
1395426422,Anne
6+
1395426422,Hailey

test/testCSVConverter2.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ describe("testCSVConverter2", function () {
7979
});
8080
});
8181

82+
it("should parse fromFile with encoding option", function (done) {
83+
var csvFile = __dirname + "/data/dataWithLatin1Encoding";
84+
var conv = new Converter({
85+
});
86+
conv.fromFile(csvFile, { encoding: "latin1" }).then(function (json) {
87+
assert.equal(json[0].Name, 'bébé');
88+
done();
89+
});
90+
});
91+
8292
it("should fromFile should emit error", function (done) {
8393
var csvFile = __dirname + "/data/dataWithUnclosedQuotes";
8494
var conv = new Converter({

0 commit comments

Comments
 (0)