# All files ProcessorLocal.test.ts

100% Statements 31/31
100% Branches 0/0
100% Functions 6/6
100% Lines 29/29

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
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    411x
    1x

    1x
    1x
    1x

    1x
    1x
    1x
    1x
    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);
      })
      it ("should return empty array if preRawHook removed the data",()=>{
        const conv=new Converter();
        conv.preRawData((str)=>{
          return "";
        });
        const processor=new ProcessorLocal(conv);
        const data=readFileSync(dataDir+"/complexJSONCSV");
        return processor.process(data)
        .then((list)=>{
          assert.equal(list.length,0);
        })
      })
    })