Skip to content

Commit 6098902

Browse files
committed
tmp: no buffer
1 parent e4069e1 commit 6098902

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

scripts/ciTest.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if (all) {
3737
formatTest = true;
3838
}
3939

40-
function runTests() {
40+
async function runTests() {
4141
if (ounitTest) {
4242
cp.execSync(path.join(duneBinDir, "ounit_tests"), {
4343
stdio: [0, 1, 2],
@@ -56,7 +56,13 @@ function runTests() {
5656
console.log("Doing build_tests");
5757
var buildTestDir = path.join(__dirname, "..", "jscomp", "build_tests");
5858
var files = fs.readdirSync(buildTestDir);
59-
files.forEach(function (file) {
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+
});
6066
var testDir = path.join(buildTestDir, file);
6167
if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) {
6268
return;
@@ -65,23 +71,38 @@ function runTests() {
6571
console.warn(`input.js does not exist in ${testDir}`);
6672
} else {
6773
console.log(`testing ${file}`);
74+
6875
// note existsSync test already ensure that it is a directory
69-
cp.exec(
70-
`node input.js`,
71-
{ cwd: testDir, encoding: "utf8" },
72-
function (error, stdout, stderr) {
73-
console.log(stdout);
74-
75-
if (error !== null) {
76-
console.log(`❌ error in ${file} with stderr:\n`, stderr);
77-
throw error;
78-
} else {
79-
console.log("✅ success in", file);
80-
}
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);
8196
}
82-
);
97+
// @ts-ignore
98+
resolve();
99+
});
83100
}
101+
102+
return promise;
84103
});
104+
105+
await Promise.all(tasks);
85106
}
86107

87108
if (formatTest) {
@@ -92,9 +113,9 @@ function runTests() {
92113
}
93114
}
94115

95-
function main() {
116+
async function main() {
96117
try {
97-
runTests();
118+
await runTests();
98119
} catch (err) {
99120
console.error(err);
100121
process.exit(2);

0 commit comments

Comments
 (0)