-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_test_cases.js
37 lines (32 loc) · 1.1 KB
/
generate_test_cases.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
const { writeFile, mkdir, readdir } = require("fs/promises");
const elmCompiler = require("node-elm-compiler");
const { resolve, dirname, parse } = require("path");
const testCaseDir = resolve(__dirname, "gen_test_cases");
const generate = async (pathToTestCase) => {
const testCaseName = parse(pathToTestCase).name;
const name = testCaseName.replace("Case", "");
const worker = await elmCompiler.compileWorker(
__dirname,
pathToTestCase,
testCaseName,
{ flags: { name } }
);
worker.ports.sendFile.subscribe(async ({ path, content }) => {
const targetPath = resolve(__dirname, path);
await mkdir(dirname(targetPath), { recursive: true });
await writeFile(resolve(__dirname, path), content);
worker.ports.sendFile.unsubscribe();
});
};
const generateTestCases = async () => {
const [, , filePath] = process.argv;
if (filePath) {
generate(filePath);
return;
}
const fileNames = await readdir(testCaseDir);
fileNames
.filter((fileName) => fileName.endsWith("Case.elm"))
.map((fileName) => generate(resolve(testCaseDir, fileName)));
};
generateTestCases();