forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciTest.js
116 lines (102 loc) · 2.5 KB
/
ciTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//@ts-check
var cp = require("child_process");
var path = require("path");
var fs = require("fs");
var duneBinDir = require("./dune").duneBinDir;
var ounitTest = false;
var mochaTest = false;
var themeTest = false;
var bsbTest = false;
var formatTest = false;
var all = false;
if (process.argv.includes("-ounit")) {
ounitTest = true;
}
if (process.argv.includes("-mocha")) {
mochaTest = true;
}
if (process.argv.includes("-theme")) {
themeTest = true;
}
if (process.argv.includes("-bsb")) {
bsbTest = true;
}
if (process.argv.includes("-format")) {
formatTest = true;
}
if (process.argv.includes("-all")) {
all = true;
}
if (all) {
ounitTest = true;
mochaTest = true;
themeTest = true;
bsbTest = true;
formatTest = true;
}
function runTests() {
if (ounitTest) {
cp.execSync(path.join(duneBinDir, "ounit_tests"), {
stdio: [0, 1, 2],
});
}
// running generated js tests
if (mochaTest) {
cp.execSync(`npx mocha -t 10000 jscomp/test/**/*test.js`, {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
if (bsbTest) {
console.log("Doing build_tests");
var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests");
var linkCmd = `npm link ../..`;
console.log(linkCmd);
cp.execSync(linkCmd, {
cwd: buildTestDir,
stdio: [0, 1, 2],
encoding: "utf8",
});
var files = fs.readdirSync(buildTestDir);
files.forEach(function (file) {
var testDir = path.join(buildTestDir, file);
if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) {
return;
}
if (!fs.existsSync(path.join(testDir, "input.js"))) {
console.warn(`input.js does not exist in ${testDir}`);
} else {
console.log(`testing ${file}`);
// note existsSync test already ensure that it is a directory
cp.exec(
`node input.js`,
{ cwd: testDir, encoding: "utf8" },
function (error, stdout, stderr) {
console.log(stdout);
if (error !== null) {
console.log(stderr);
throw new Error(`❌ error in ${file}: \n${error} `);
} else {
console.log("✅ success in ", file);
}
}
);
}
});
}
if (formatTest) {
cp.execSync("npm run checkFormat", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
}
function main() {
try {
runTests();
} catch (err) {
console.error(err);
process.exit(2);
}
}
main();