From 6613cbac446502aedaf9f78f8ee0ada42947a36b Mon Sep 17 00:00:00 2001 From: Greg Walker Date: Thu, 15 Sep 2022 14:20:26 -0500 Subject: [PATCH] use csv-parse to test csv correctness --- src/scripts/q-expand.test.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/scripts/q-expand.test.js b/src/scripts/q-expand.test.js index 25efa5e2..6016fe77 100644 --- a/src/scripts/q-expand.test.js +++ b/src/scripts/q-expand.test.js @@ -1,4 +1,5 @@ const fs = require("fs"); +const { parse } = require("csv-parse"); const { getApp } = require("../utils/test"); const script = require("./q-expand"); @@ -244,13 +245,19 @@ describe("q-expand csv data", () => { } }); - it("is formatted correctly", () => { - const csv = fs - .readFileSync("config/q-expand.csv", { encoding: "utf-8" }) - .trim() - .split("\n"); - const lines = csv.map((line) => line.split(",")); - const invalid = lines.filter((parts) => parts.length !== 2); - expect(invalid.length).toBe(0); - }); + it("is formatted correctly", async () => + new Promise((resolve) => { + const rows = []; + + fs.createReadStream("config/q-expand.csv") + .pipe(parse({ delimiter: "," })) + .on("data", (row) => { + rows.push(row); + }) + .on("end", () => { + const invalid = rows.filter((row) => row.length !== 2); + expect(invalid.length).toBe(0); + resolve(); + }); + })); });