]> git.ardis.lu - csvio/commitdiff
Strictly count the number of batches
authorArdis Lu <ardisglu@gmail.com>
Thu, 29 May 2025 04:00:02 +0000 (21:00 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 29 May 2025 04:00:02 +0000 (21:00 -0700)
test/core.test.js

index 1fe7f5bde0539439c9a3a1fe550d6b55b862fca9..366c0b1b43dfd9f72436514f694c0e92299d0182 100644 (file)
@@ -441,65 +441,73 @@ suite('CSVTransformer', { concurrency: true }, () => {
       { name: 'Error', message: 'Not an error type' }
     );
   });
-  test('creates batch of 1 when maxBatchSize is equal to 1', { concurrency: true }, async () => {
+  test('creates batch of 1 when maxBatchSize is equal to 1', { concurrency: true }, async (t) => {
+    const fn = t.mock.fn(b => b.map(r => r.map(f => Number(f) * 2)));
     await createCSVMockStream([
       ['columnA', 'columnB'],
       ['1', '2'],
       ['3', '4'],
       ['5', '6']
     ])
-      .pipeThrough(new CSVTransformer(b => b.map(r => r.map(f => Number(f) * 2)), { maxBatchSize: 1 }))
+      .pipeThrough(new CSVTransformer(fn, { maxBatchSize: 1 }))
       .pipeTo(csvStreamEqualWritable([
         ['columnA', 'columnB'],
         [2, 4],
         [6, 8],
         [10, 12]
       ]));
+    deepStrictEqual(fn.mock.callCount(), 3);
   });
-  test('creates one batch when maxBatchSize is greater than CSV row length', { concurrency: true }, async () => {
+  test('creates one batch when maxBatchSize is greater than CSV row length', { concurrency: true }, async (t) => {
+    const fn = t.mock.fn(b => b.map(r => r.map(f => Number(f) * 2)));
     await createCSVMockStream([
       ['columnA', 'columnB'],
       ['1', '2'],
       ['3', '4'],
       ['5', '6']
     ])
-      .pipeThrough(new CSVTransformer(b => b.map(r => r.map(f => Number(f) * 2)), { maxBatchSize: 100 }))
+      .pipeThrough(new CSVTransformer(fn, { maxBatchSize: 100 }))
       .pipeTo(csvStreamEqualWritable([
         ['columnA', 'columnB'],
         [2, 4],
         [6, 8],
         [10, 12]
       ]));
+    deepStrictEqual(fn.mock.callCount(), 1);
   });
-  test('creates one batch when maxBatchSize is equal to CSV row length', { concurrency: true }, async () => {
+  test('creates one batch when maxBatchSize is equal to CSV row length', { concurrency: true }, async (t) => {
+    const fn = t.mock.fn(b => b.map(r => r.map(f => Number(f) * 2)));
     await createCSVMockStream([
       ['columnA', 'columnB'],
       ['1', '2'],
       ['3', '4'],
       ['5', '6']
     ])
-      .pipeThrough(new CSVTransformer(b => b.map(r => r.map(f => Number(f) * 2)), { maxBatchSize: 3 }))
+      .pipeThrough(new CSVTransformer(fn, { maxBatchSize: 3 }))
       .pipeTo(csvStreamEqualWritable([
         ['columnA', 'columnB'],
         [2, 4],
         [6, 8],
         [10, 12]
       ]));
+    deepStrictEqual(fn.mock.callCount(), 1);
   });
-  test('creates multiple batches when maxBatchSize is less than CSV row length', { concurrency: true }, async () => {
+  test('creates multiple batches when maxBatchSize is less than CSV row length', { concurrency: true }, async (t) => {
+    const fn = t.mock.fn(b => b.map(r => r.map(f => Number(f) * 2)));
     await createCSVMockStream([
       ['columnA', 'columnB'],
       ['1', '2'],
       ['3', '4'],
       ['5', '6']
     ])
-      .pipeThrough(new CSVTransformer(b => b.map(r => r.map(f => Number(f) * 2)), { maxBatchSize: 2 }))
+      .pipeThrough(new CSVTransformer(fn, { maxBatchSize: 2 }))
       .pipeTo(csvStreamEqualWritable([
         ['columnA', 'columnB'],
         [2, 4],
         [6, 8],
         [10, 12]
       ]));
+    deepStrictEqual(fn.mock.callCount(), 2);
   });
 });
 
This page took 0.042284 seconds and 4 git commands to generate.