-
Notifications
You must be signed in to change notification settings - Fork 362
/
index.js
64 lines (59 loc) · 1.84 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict';
const tape = require('tape');
const loadFixtures = require('./helpers/loadFixtures');
const CLI = require('./CLI');
const JSON2CSVParser = require('./JSON2CSVParser');
const JSON2CSVAsyncParser = require('./JSON2CSVAsyncParser');
const JSON2CSVAsyncParserInMemory = require('./JSON2CSVAsyncParserInMemory');
const JSON2CSVStreamParser = require('./JSON2CSVStreamParser');
const JSON2CSVTransform = require('./JSON2CSVTransform');
const parseNdjson = require('./parseNdjson');
const testRunner = {
tests: [],
before: [],
after: [],
add(name, test) {
this.tests.push({ name, test });
},
addBefore(func) {
this.before.push(func);
},
addAfter(func) {
this.after.push(func);
},
async run() {
try {
await Promise.all(testRunner.before.map(before => before()));
this.tests.forEach(({ name, test }) => tape(name, async (t) => {
try {
await test(t);
} catch (err) {
t.fail(err);
}
}));
this.after.forEach(after => tape.onFinish(after));
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
}
}
};
async function loadAllFixtures() {
return Promise.all([
loadFixtures.loadJSON(),
loadFixtures.loadJSONStreams(),
loadFixtures.loadCSV()
]);
}
async function setupTests([jsonFixtures, jsonFixturesStreams, csvFixtures]) {
CLI(testRunner, jsonFixtures, csvFixtures);
JSON2CSVParser(testRunner, jsonFixtures, csvFixtures);
JSON2CSVAsyncParser(testRunner, jsonFixturesStreams, csvFixtures);
JSON2CSVAsyncParserInMemory(testRunner, jsonFixtures, csvFixtures);
JSON2CSVStreamParser(testRunner, jsonFixturesStreams, csvFixtures);
JSON2CSVTransform(testRunner, jsonFixturesStreams, csvFixtures);
parseNdjson(testRunner, jsonFixtures);
}
loadAllFixtures()
.then(setupTests)
.then(() => testRunner.run());