All files / csv2json/src ProcessorLocal.test.ts

100% Statements 23/23
100% Branches 0/0
100% Functions 3/3
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x 1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x        
import {ProcessorLocal} from "./ProcessorLocal";
import { Converter } from "./Converter";
import P from "bluebird";
import {readFileSync} from "fs";
import path from "path";
import assert from "assert";
import { JSONResult } from "./lineToJson";
const dataDir=path.join(__dirname,"../test/data/");
describe("ProcessLocal",()=>{
  it ("should process csv chunks and output json",async function (){
    const processor=new ProcessorLocal(new Converter());
    const data=readFileSync(dataDir+"/complexJSONCSV");
    const lines=await processor.process(data);
    assert(lines.length === 2);
    const line0=lines[0] as JSONResult;
    assert.equal(line0.fieldA.title,"Food Factory");
    assert.equal(line0.fieldA.children.length,2);
    assert.equal(line0.fieldA.children[1].employee[0].name,"Tim");
  })
  it ("should process csv chunks and output csv rows",async function (){
    const processor=new ProcessorLocal(new Converter({output:"line"}));
    const data=readFileSync(dataDir+"/complexJSONCSV");
    const lines=await processor.process(data);
    
    assert(lines.length === 2);
  })
})