From: Ardis Lu Date: Thu, 29 May 2025 04:00:02 +0000 (-0700) Subject: Strictly count the number of batches X-Git-Tag: v0.1.0~7 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=246bd0f83c8bde6e7ed502fe4121b573e9990002;p=csvio Strictly count the number of batches --- diff --git a/test/core.test.js b/test/core.test.js index 1fe7f5b..366c0b1 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -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); }); });