From fe3acfbc2bdf465a24ca0ffcd569b17b566040fa Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 10 Feb 2025 22:33:25 -0800 Subject: [PATCH] Add additional tests for uncovered branches --- test/core.test.js | 11 ++++++++++ test/normalization.test.js | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/test/core.test.js b/test/core.test.js index a02e4bd..3f0099f 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -212,6 +212,17 @@ suite('CSVTransformer', { concurrency: true }, () => { .pipeThrough(new CSVTransformer(r => r)) .pipeTo(csvStreamEqualWritable(csv)); }); + test('passes through raw input', { concurrency: true }, async () => { + await ReadableStream.from((function* () { + yield '["headerA","headerB"]'; + yield '["111","222"]'; + })()) + .pipeThrough(new CSVTransformer(r => r, { handleHeaders: true, rawInput: true })) + .pipeTo(csvStreamEqualWritable([ + ['headerA', 'headerB'], + ['111', '222'] + ])); + }); test('passes through raw output', { concurrency: true }, async () => { await createCSVMockStream([ ['columnA', 'columnB'], diff --git a/test/normalization.test.js b/test/normalization.test.js index 3463a23..1f01b8f 100644 --- a/test/normalization.test.js +++ b/test/normalization.test.js @@ -207,6 +207,51 @@ suite('CSVNormalizer', { concurrency: true }, () => { ['a', 'b'] ])); }); + test('can pass through numbers', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['123', '456'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'number' }, + { name: 'columnB', type: 'number' } + ], { passthroughNumber: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['123', '456'] + ])); + }); + test('can pass through BigInt', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['123', '456'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'bigint' }, + { name: 'columnB', type: 'bigint' } + ], { passthroughBigInt: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['123', '456'] + ])); + }); + test('can pass through date', { concurrency: true }, async () => { + await createCSVMockStream([ + ['columnA', 'columnB'], + ['2025-02-10', '2025-02-09'] + ]) + .pipeThrough(new CSVNormalizer([ + { name: 'columnA', type: 'date' }, + { name: 'columnB', type: 'date' } + ], { passthroughDate: true })) + .pipeThrough(new CSVDenormalizer()) + .pipeTo(csvStreamEqualWritable([ + ['columnA', 'columnB'], + ['2025-02-10', '2025-02-09'] + ])); + }); test('can ignore incorrect data types', { concurrency: true }, async (t) => { assertConsole(t, { warn: 2 }); await createCSVMockStream([ -- 2.47.3