Skip to content

Commit

Permalink
test(csv-issues-cjs): reproduce issue 327
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 25, 2023
1 parent 57cee1b commit a70ffab
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions demo/issues-cjs/lib/327.cws.buf.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
field1,field2
Acentuação1,acentuação2
2 changes: 2 additions & 0 deletions demo/issues-cjs/lib/327.cws.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
field1,field2
Acentua��o1,acentua��o2
32 changes: 32 additions & 0 deletions demo/issues-cjs/lib/327.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { stringify } = require('csv-stringify');
const fs = require('fs');

(() => {
const stringifier = stringify({
defaultEncoding: 'latin1',
});
stringifier.pipe(
fs.createWriteStream(__dirname+'/327.stringifier.csv')
);
stringifier.write(['field1', 'field2']);
stringifier.write(['Acentuação1', 'acentuação2']);
stringifier.end();
})();

(() => {
const out = fs.createWriteStream(__dirname+'/327.cws.csv', {
encoding: 'latin1', // <== Here the encoding works
});
out.write('field1,field2\n');
out.write('Acentuação1,acentuação2\n');
out.end();
})();

(() => {
const out = fs.createWriteStream(__dirname+'/327.cws.buf.csv', {
encoding: 'latin1', // <== Here the encoding works
});
out.write(Buffer.from('field1,field2\n', 'utf8'));
out.write(Buffer.from('Acentuação1,acentuação2\n', 'utf8'));
out.end();
})();
2 changes: 2 additions & 0 deletions demo/issues-cjs/lib/327.stringifier.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
field1,field2
Acentua��o1,acentua��o2
8 changes: 4 additions & 4 deletions demo/issues-esm/test/samples.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe 'Samples', ->
.map (sample) ->
it "Sample #{sample}", (callback) ->
ext = /\.(\w+)?$/.exec(sample)[0]
cmd = switch ext
[cmd, ...args] = switch ext
when '.js'
'node'
['node', path.resolve dir, sample]
when '.ts'
'node --loader ts-node/esm'
spawn(cmd, [path.resolve dir, sample])
['node', '--loader', 'ts-node/esm', path.resolve dir, sample]
spawn(cmd, args)
.on 'close', (code) -> callback(code isnt 0 and new Error 'Failure')
.stdout.on 'data', (->)

0 comments on commit a70ffab

Please sign in to comment.