Skip to content

Commit

Permalink
fix: Fix JSON output from ctest not being received
Browse files Browse the repository at this point in the history
'exit' spawn event does not wait for stdout to be closed.
'close' is the correct event

Also fixes the tests being flaky
  • Loading branch information
iamsergio committed Jun 5, 2024
1 parent 45a2eac commit 9cea2c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.tgz
*.log
/out/
/src/*.js
11 changes: 9 additions & 2 deletions out/cmake.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ class CMakeTests {
child.stdout.on("data", (chunk) => {
output += chunk.toString();
});
child.on("exit", (code) => {
child.on("close", (code) => {
if (code === 0) {
resolve(this.ctestJsonToList(output));
if (output.length == 0) {
console.error("ctestJsonToList: Empty json output. Command was ctest --show-only=json-v1 , in " +
this.buildDirPath);
reject(new Error("Failed to get ctest JSON output"));
}
else {
resolve(this.ctestJsonToList(output));
}
}
else {
reject(new Error("Failed to run ctest"));
Expand Down
12 changes: 10 additions & 2 deletions src/cmake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ export class CMakeTests {
output += chunk.toString();
});

child.on("exit", (code) => {
child.on("close", (code) => {
if (code === 0) {
resolve(this.ctestJsonToList(output));
if (output.length == 0) {
console.error(
"ctestJsonToList: Empty json output. Command was ctest --show-only=json-v1 , in " +
this.buildDirPath,
);
reject(new Error("Failed to get ctest JSON output"));
} else {
resolve(this.ctestJsonToList(output));
}
} else {
reject(new Error("Failed to run ctest"));
}
Expand Down

0 comments on commit 9cea2c3

Please sign in to comment.