Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {} from 'ts-jest';
- import * as parse from 'csv-parse';
- import {StreamReadCallback, StreamReadable, streamReadable} from './Readable'
- import {CsvRow, csvStreamReadApplyCallbacks} from './Readable_Csv'
- import { testing } from 'bs-logger';
- interface SpecificCSVRow {
- first: string
- second: string
- }
- describe.skip('CSV implementation', () => {
- const columns = ['first', 'second', 'third'];
- let parser: parse.Parser = parse(`
- "1","2",3
- "a","b","c"
- `, {
- trim: true,
- skip_empty_lines: true,
- columns
- })
- test('Chain several callbacks for CSV reading stream', () => {
- let genericCsvCallback: StreamReadCallback<CsvRow> = (row: CsvRow) => {
- expect(Object.keys(row)).toEqual(columns)
- }
- let specificCsvCallback: StreamReadCallback<SpecificCSVRow> = (row: SpecificCSVRow) => {
- expect(typeof row.first).toEqual('string')
- expect(typeof row.second).toEqual('string')
- }
- let memoryCollection: object[] = [];
- let memoryCallback: StreamReadCallback<CsvRow> = (row: object) => memoryCollection.push(row);
- const streamReadableCsv: StreamReadable<parse.Parser, object, parse.Parser> = streamReadable;
- streamReadableCsv(parser, csvStreamReadApplyCallbacks)(genericCsvCallback)(specificCsvCallback)(memoryCallback)().on('end', () => {
- expect(memoryCollection).toEqual([
- {first: '1', second: '2', third: '3'},
- {first: 'a', second: 'b', third: 'c'}
- ]);
- });
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement