-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(csv-parse): destroy on end and call close event (fix #333)
- Loading branch information
Showing
8 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
import * as stream from 'node:stream/promises' | ||
import { Readable } from 'stream' | ||
import { generate } from 'csv-generate' | ||
import { parse } from '../lib/index.js' | ||
|
||
describe 'API stream.finished', -> | ||
|
||
it 'resolved at the end', -> | ||
# See https://github.com/adaltas/node-csv/issues/333 | ||
records = [] | ||
parser = generate(length: 10).pipe parse() | ||
parser.on 'readable', () => | ||
while (record = parser.read()) isnt null | ||
records.push record | ||
await stream.finished parser | ||
records.length.should.eql 10 | ||
|
||
it 'resolved with `to_line`', -> | ||
# See https://github.com/adaltas/node-csv/issues/333 | ||
records = [] | ||
parser = generate(length: 10).pipe parse to_line: 3 | ||
parser.on 'readable', () => | ||
while (record = parser.read()) isnt null | ||
records.push record | ||
await stream.finished parser | ||
records.length.should.eql 3 | ||
|
||
it 'rejected on error', -> | ||
parser = parse to_line: 3 | ||
parser.write 'a,b,c\n' | ||
parser.write 'd,e,f\n' | ||
parser.write 'h,i,j,ohno\n' | ||
parser.write 'k,l,m\n' | ||
parser.end() | ||
parser.on 'readable', () => | ||
while (record = parser.read()) isnt null then true | ||
stream | ||
.finished parser | ||
.should.be.rejectedWith | ||
code: 'CSV_RECORD_INCONSISTENT_FIELDS_LENGTH' |