From: Ardis Lu Date: Tue, 28 Jan 2025 06:22:55 +0000 (-0800) Subject: Add tests for writing raw CSV strings X-Git-Tag: v0.1.0~79 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=14d26004a1c278730b9432f9f3498fb240acd957;p=csvio Add tests for writing raw CSV strings --- diff --git a/test/core.test.js b/test/core.test.js index 75b298f..dedbc42 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -506,6 +506,19 @@ suite('CSVWriter', { concurrency: true }, () => { await new CSVReader(temp).pipeTo(csvStreamEqualWritable(csv)); }); } + test('writes raw CSV string', { concurrency: true, only: true }, async (t) => { + const temp = await createTempFile(); + t.after(async () => await unlink(temp)); + await createCSVMockStream([['']]) + .pipeThrough(new CSVTransformer(() => 'row 1,a\r\nrow 2,b\r\nrow 3,c', { handleHeaders: true, rawOutput: true })) + .pipeTo(new CSVWriter(temp)); + await new CSVReader(temp).pipeTo( + csvStreamEqualWritable([ + ['row 1', 'a'], + ['row 2', 'b'], + ['row 3', 'c'] + ])); + }); }); suite('CSVWriter status', { concurrency: true }, () => { @@ -547,4 +560,13 @@ suite('CSVWriter status', { concurrency: true }, () => { await createCSVMockStream([['']]).pipeTo(writer); ok(writer.status.done); }); + test('counts raw CSV string as one row', { concurrency: true }, async (t) => { + const temp = await createTempFile(); + t.after(async () => await unlink(temp)); + const writer = new CSVWriter(temp); + await createCSVMockStream([['']]) + .pipeThrough(new CSVTransformer(() => 'row 1,a\r\nrow 2,b\r\nrow 3,c'), { handleHeaders: true, rawOutput: true }) + .pipeTo(writer); + deepStrictEqual(writer.status.rows, 1); + }); }); \ No newline at end of file