Skip to content

Commit

Permalink
Merge pull request #451 from 18F/mgwalker/update-qex-test
Browse files Browse the repository at this point in the history
Use csv-parse to test CSV correctness
  • Loading branch information
geekygirlsarah authored Sep 16, 2022
2 parents c50cf77 + 6613cba commit 0768aaa
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/scripts/q-expand.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require("fs");
const { parse } = require("csv-parse");

const { getApp } = require("../utils/test");
const script = require("./q-expand");
Expand Down Expand Up @@ -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();
});
}));
});

0 comments on commit 0768aaa

Please sign in to comment.