import “mocha”;
    import { expect } from “chai”;

    import csv from “fast-csv”;
    import { execFile } from “child_process”;
    import iconv from “iconv-lite”;
    import ParseCode from “../src/Index”;

    export function ReadCsv(len = 10) {
    const path = “./test/temp/json_arr.csv”;
    const arr: string[] = [];

    return new Promise(resolve => {
    csv
    .fromPath(path, { headers: false })
    .on(“data”, data => {
    const code = data[0];
    if (code == null || arr.length >= len) return;
    if (code.indexOf(“[“) !== 0) return;
    arr.push(code);
    })
    .on(“end”, function() {
    console.log(“done”);
    resolve(arr);
    });
    });
    }

    export function GetTestResult(code: string, dep = “PEK”) {
    const result = ParseCode(code, dep);
    return TestClean(result);
    }

    export function GetResult(code: string) {
    const path = “./test/net_app/IataParseConsole.exe”;
    const params = [code, “PEK”, “utf8”];

    return new Promise((resolve, reject) => {
    execFile(path, params, { encoding: “buffer” }, (error, stdout, stderr) => {
    if (error) {
    reject(error);
    return;
    }
    const json = iconv.decode(stdout, “utf8”);
    let result = JSON.parse(json);
    result = TestClean(result);
    resolve(result);
    });
    });
    }

    export function TestClean(obj: object) {
    for (var propName in obj) {
    if (obj[propName] === null || obj[propName] === undefined) {
    delete obj[propName];
    }
    }
    return JSON.parse(JSON.stringify(obj));
    }

    export function TestCode(code) {
    it(code, async () => {
    let result2;

    1. try {<br /> result2 = await GetResult(code);<br /> } catch (err) {<br /> debugger;<br /> console.error(err);<br /> return;<br /> }
    2. const result1 = GetTestResult(code);<br /> expect(result2).to.deep.equal(result1);<br /> });<br />}