Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(csv-parse): error thrown by webstream
  • Loading branch information
wdavidw committed Nov 20, 2024
commit d33a61a8a575f8a48545fc7e20fc56221ad339dc
28 changes: 21 additions & 7 deletions packages/csv-parse/test/api.web_stream.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
import assert from 'assert';
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 () => {
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();

assert.deepStrictEqual(await reader.read(), {
await reader.read().should.finally.eql({
done: false,
value: ['A', 'B', 'C'],
});
assert.deepStrictEqual(await reader.read(), {
await reader.read().should.finally.eql({
done: false,
value: ['D', 'E', 'F'],
});
assert.deepStrictEqual(await reader.read(), {
await reader.read().should.finally.eql({
done: true,
value: undefined,
});
})

it("cat error parse", async function () {
const stream = parseStream();
const writer = stream.writable.getWriter();
try {
await writer.write(Buffer.from("A,B,C\nD,E"));
await writer.close();
throw Error("Shall not be called");
} catch (err) {
if (!(err instanceof CsvError)) {
throw Error("Invalid error type");
}
err.code.should.eql("CSV_RECORD_INCONSISTENT_FIELDS_LENGTH");
}
});

})
})