-
Notifications
You must be signed in to change notification settings - Fork 1
/
read.spec.js
49 lines (43 loc) · 1.73 KB
/
read.spec.js
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
41
42
43
44
45
46
47
48
49
import {strict as assert} from "assert";
import path from "path";
import * as _ from "lamb";
import {readCsv, readJson, readJsonDir} from "../src/read";
/* ab.csv */
describe("read", function() {
describe("readCsv", function() {
it("should return a promise that reads and then parses a csv file",
async function() {
const csvPath = path.resolve(__dirname, "./_assets", "ab.csv");
const conversionFn = row => ({
a: row.a,
b: Number(row.b)
});
const csv = await readCsv(csvPath, conversionFn);
const csvParsed = [{a: "foo", b: 1}, {a: "bar", b: 2}];
csvParsed.columns = ["a", "b"];
assert.deepStrictEqual(csv, csvParsed);
}
);
});
describe("readJson", function() {
it("should return a promise that reads and then parses a json file",
async function() {
const aPath = path.resolve(__dirname, "./_assets", "a1.json");
const a = await readJson(aPath);
assert.deepStrictEqual(a, {a: 1});
const bPath = path.resolve(__dirname, "./_assets", "b2.json");
const b = await readJson(bPath);
assert.deepStrictEqual(b, {b: 2});
}
);
});
describe("readJsonDir", function() {
it("should return a promise returning an array of objects of the json files of a directory",
async function() {
const dirPath = path.resolve(__dirname, "./_assets");
const jsons = await readJsonDir(dirPath);
assert.deepStrictEqual(jsons, [{a: 1}, {b: 2}]);
}
);
});
});