Skip to content

Commit

Permalink
refactor(csv-parse): websream controller.error without thrown error
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 20, 2024
1 parent f9aeaa0 commit a409803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
4 changes: 0 additions & 4 deletions packages/csv-parse/lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ const parse = (opts) => {
},
transform(chunk) {
const error = api.parse(chunk, false, enqueue, terminate);

if (error) {
controller.error(error);
throw error;
}
},
flush() {
const error = api.parse(undefined, true, enqueue, terminate);

if (error) {
controller.error(error);
throw error;
}
},
},
Expand Down
27 changes: 12 additions & 15 deletions packages/csv-parse/test/api.web_stream.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import 'should'
import {parse as parseStream} from '../lib/stream.js'
import { CsvError } from '../lib/index.js'
import "should";
import { parse as parseStream } from "../lib/stream.js";
import { CsvError } from "../lib/index.js";

describe('API Web Stream', () => {

describe('stream/web/TransformStream', () => {

it('simple parse', async () => {
describe("API Web Stream", () => {
describe("stream/web/TransformStream", () => {
it("simple parse", async () => {
const stream = parseStream();
const writer = stream.writable.getWriter();
const reader = stream.readable.getReader();
await writer.write(Buffer.from("A,B,C\nD,E,F"));
await writer.close();
await reader.read().should.finally.eql({
done: false,
value: ['A', 'B', 'C'],
value: ["A", "B", "C"],
});
await reader.read().should.finally.eql({
done: false,
value: ['D', 'E', 'F'],
value: ["D", "E", "F"],
});
await reader.read().should.finally.eql({
done: true,
value: undefined,
});
})
});

it("cat error parse", async function () {
const stream = parseStream();
const writer = stream.writable.getWriter();
Expand All @@ -40,6 +38,5 @@ describe('API Web Stream', () => {
err.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH");
}
});

})
})
});
});

0 comments on commit a409803

Please sign in to comment.