Skip to content

Commit

Permalink
[BREAKING] JSDoc: Fail build when jsdoc command failed (#845)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
The `jsdocGenerator` processor and the corresponding `generateJsdoc` task will now throw an error when JSDoc reports an error (exit code != 0). This will also fail the build when running `ui5 build jsdoc`.
  • Loading branch information
matz3 committed Nov 18, 2022
1 parent 61e709d commit c2916b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 6 additions & 8 deletions lib/processors/jsdoc/jsdocGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ async function buildJsdoc({sourcePath, configPath}) {
"--verbose",
sourcePath
];
return new Promise((resolve, reject) => {
const exitCode = await new Promise((resolve /* , reject */) => {
const child = spawn("node", args, {
stdio: ["ignore", "ignore", "inherit"]
});
child.on("close", function(code) {
if (code === 0 || code === 1) {
resolve();
} else {
reject(new Error(`JSDoc child process closed with code ${code}`));
}
});
child.on("close", resolve);
});

if (exitCode !== 0) {
throw new Error(`JSDoc reported an error, check the log for issues (exit code: ${exitCode})`);
}
}

jsdocGenerator._generateJsdocConfig = generateJsdocConfig;
Expand Down
8 changes: 5 additions & 3 deletions test/lib/processors/jsdoc/jsdocGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,20 @@ test.serial("buildJsdoc", async (t) => {

// Re-execute with exit code 1
exitCode = 1;
await t.notThrowsAsync(jsdocGenerator._buildJsdoc({
await t.throwsAsync(jsdocGenerator._buildJsdoc({
sourcePath: "/some/path",
configPath: "/some/config/path/jsdoc-config.json"
}));
}), {
message: "JSDoc reported an error, check the log for issues (exit code: 1)"
});

// Re-execute with exit code 2
exitCode = 2;
const error = await t.throwsAsync(jsdocGenerator._buildJsdoc({
sourcePath: "/some/path",
configPath: "/some/config/path/jsdoc-config.json"
}));
t.is(error.message, "JSDoc child process closed with code 2");
t.is(error.message, "JSDoc reported an error, check the log for issues (exit code: 2)");
});

test.serial("jsdocGenerator", async (t) => {
Expand Down

0 comments on commit c2916b4

Please sign in to comment.