Skip to content

Commit cf616c3

Browse files
committed
clean ciTest script
1 parent 3d47b87 commit cf616c3

File tree

2 files changed

+17
-49
lines changed

2 files changed

+17
-49
lines changed

jscomp/build_tests/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const signals = {
77
SIGTERM: 15,
88
};
99

10-
async function exec(command, args) {
10+
async function exec(command, args, options = { cwd: __dirname }) {
1111
const stdoutChunks = [];
1212
const stderrChunks = [];
1313

1414
const subprocess = child_process.spawn(command, args, {
1515
stdio: ["ignore", "pipe", "pipe"],
16-
cwd: __dirname,
16+
cwd: options.cwd,
1717
});
1818

1919
subprocess.stdout.on("data", chunk => {
@@ -25,11 +25,11 @@ async function exec(command, args) {
2525
});
2626

2727
return await new Promise((resolve, reject) => {
28-
subprocess.on("error", err => {
28+
subprocess.once("error", err => {
2929
reject(err);
3030
});
3131

32-
subprocess.on("close", (exitCode, signal) => {
32+
subprocess.once("close", (exitCode, signal) => {
3333
const stdout = Buffer.concat(stdoutChunks).toString("utf8");
3434
const stderr = Buffer.concat(stderrChunks).toString("utf8");
3535

scripts/ciTest.js

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var fs = require("fs");
55

66
var duneBinDir = require("./dune").duneBinDir;
77

8+
const { exec } = require("../jscomp/build_tests/utils.js");
9+
810
var ounitTest = false;
911
var mochaTest = false;
1012
var bsbTest = false;
@@ -56,13 +58,7 @@ async function runTests() {
5658
console.log("Doing build_tests");
5759
var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests");
5860
var files = fs.readdirSync(buildTestDir);
59-
var tasks = files.map(async function (file) {
60-
// @ts-ignore
61-
let resolve, reject;
62-
let promise = new Promise((res, rej) => {
63-
resolve = res;
64-
reject = rej;
65-
});
61+
for (const file of files) {
6662
var testDir = path.join(buildTestDir, file);
6763
if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) {
6864
return;
@@ -73,36 +69,16 @@ async function runTests() {
7369
console.log(`testing ${file}`);
7470

7571
// note existsSync test already ensure that it is a directory
76-
let p = cp.spawn(`node`, ["input.js"], { cwd: testDir });
77-
78-
p.stdout.setEncoding("utf8").on("data", line => {
79-
console.log(line);
80-
});
81-
82-
let stderr = "";
83-
p.stderr.setEncoding("utf8").on("data", line => {
84-
stderr += line + "\n";
85-
});
86-
87-
p.once("error", err => {
88-
console.log(`❌ error in ${file} with stderr:\n`, stderr);
89-
// @ts-ignore
90-
reject(err);
91-
});
92-
93-
p.once("close", () => {
94-
if (!stderr) {
95-
console.log("✅ success in", file);
96-
}
97-
// @ts-ignore
98-
resolve();
99-
});
72+
const out = await exec(`node`, ["input.js"], { cwd: testDir });
73+
console.log(out.stdout);
74+
75+
if (out.status === 0) {
76+
console.log("✅ success in", file);
77+
} else {
78+
console.log(`❌ error in ${file} with stderr:\n`, out.stderr);
79+
}
10080
}
101-
102-
return promise;
103-
});
104-
105-
await Promise.all(tasks);
81+
}
10682
}
10783

10884
if (formatTest) {
@@ -113,12 +89,4 @@ async function runTests() {
11389
}
11490
}
11591

116-
async function main() {
117-
try {
118-
await runTests();
119-
} catch (err) {
120-
console.error(err);
121-
process.exit(2);
122-
}
123-
}
124-
main();
92+
runTests();

0 commit comments

Comments
 (0)