Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] JSDoc: Fail build when jsdoc command failed #845

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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