]> git.ardis.lu - csvio/commitdiff
Add tests for writing raw CSV strings
authorArdis Lu <ardisglu@gmail.com>
Tue, 28 Jan 2025 06:22:55 +0000 (22:22 -0800)
committerArdis Lu <ardisglu@gmail.com>
Tue, 28 Jan 2025 06:22:55 +0000 (22:22 -0800)
test/core.test.js

index 75b298f17daba12935af8ded53926c12a9a5a75e..dedbc42d1d6486883aa96a73fe6a2edd68263237 100644 (file)
@@ -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
This page took 0.057205 seconds and 4 git commands to generate.