Skip to content

Commit

Permalink
feat(csv-issues-esm): issue 411 reproductible attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed May 13, 2024
1 parent c255eb5 commit 6c5cb5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions demo/issues-esm/lib/411.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
id,amount,timestamp
1,$33.60,05/26/2022
2,$91.47,08/24/2022
3,$88.70,06/15/2022
4,$46.97,06/11/2022,faulty
5,$93.78,05/05/2022
6,$56.80,05/07/2022
7,$3.54,05/12/2022
8,$57.59,07/05/2022
9,$76.49,05/02/2022
27 changes: 27 additions & 0 deletions demo/issues-esm/lib/411.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import assert from 'node:assert';
import { createReadStream } from 'node:fs';
import { Writable } from 'node:stream'
import { finished } from 'node:stream/promises';
import desm from "desm";
import { parse } from 'csv-parse';

const __dirname = desm(import.meta.url);
const errors = []

const parser = parse({
bom: true,
skipRecordsWithError: true,
});
// Create a stream and consume its source
const sink = new Writable ({objectMode: true, write: (_, __, callback) => callback()})
const outStream = createReadStream(`${__dirname}/411.csv`).pipe(parser).pipe(sink);
// Catch records with errors
parser.on('skip', (e) => {
errors.push(e);
});
// Wait for stream to be consumed
await finished(outStream);
// Catch error from skip event
assert.deepStrictEqual(errors.map(e => e.message), [
'Invalid Record Length: expect 3, got 4 on line 5'
])

0 comments on commit 6c5cb5e

Please sign in to comment.