From 246bd0f83c8bde6e7ed502fe4121b573e9990002 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 28 May 2025 21:00:02 -0700 Subject: [PATCH] Strictly count the number of batches --- test/core.test.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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); }); }); -- 2.47.3