Skip to content

Commit

Permalink
chore(csv): use TextDecoderStream() in test (denoland#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua committed Nov 17, 2023
1 parent 2d20778 commit 9589c3f
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions csv/csv_parse_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,27 +342,14 @@ x,,,
},
});

// Work around resource leak error with TextDecoderStream:
// https://github.com/denoland/deno/issues/13142
export const MyTextDecoderStream = () => {
const textDecoder = new TextDecoder();
return new TransformStream({
transform(chunk: Uint8Array, controller: TransformStreamDefaultController) {
controller.enqueue(textDecoder.decode(chunk));
},
flush(controller: TransformStreamDefaultController) {
controller.enqueue(textDecoder.decode());
},
});
};

Deno.test({
name:
"[csv/csv_parse_stream] cancel CsvParseStream during iteration does not leak file",
permissions: { read: [testdataDir] },
fn: async () => {
const file = await Deno.open(join(testdataDir, "large.csv"));
const readable = file.readable.pipeThrough(MyTextDecoderStream())
const readable = file.readable
.pipeThrough(new TextDecoderStream())
.pipeThrough(new CsvParseStream());
for await (const _record of readable) {
break;
Expand Down

0 comments on commit 9589c3f

Please sign in to comment.