Skip to content

Commit

Permalink
fix(create-plugin): exit-code should be non-zero when an error occurs (
Browse files Browse the repository at this point in the history
…#2760)

Co-authored-by: Tuan Pham <[email protected]>
  • Loading branch information
hung-cybo and tuanphamcybozu authored May 15, 2024
1 parent 2586a7a commit 0186ba8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/create-plugin/__e2e__/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("create-plugin", function () {
const response = await createPlugin.executeCommand();

if (isWindows) {
assert.equal(response.status, 0);
assert.equal(response.status, 1);
assert.match(
response.stderr.trim(),
/Could not create a plug-in project. Error:\nEINVAL: invalid argument, mkdir '.*:'/,
Expand Down
63 changes: 63 additions & 0 deletions packages/create-plugin/__e2e__/fixtures/forbiddenCharacters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { TestPattern } from "../e2e.test";
import {
ANSWER_NO,
CREATE_PLUGIN_COMMAND,
DEFAULT_ANSWER,
} from "../utils/constants";
import { getBoundMessage } from "../../src/messages";

const m = getBoundMessage("en");
let outputDir: string;
let expectedStderr: string;
const isWindows = process.platform === "win32";
if (isWindows) {
outputDir = ":";
expectedStderr = `Could not create a plug-in project. Error:\\nEINVAL: invalid argument, mkdir '.*:'`;
} else {
outputDir = "/";
expectedStderr = `Error: ${outputDir} already exists. Choose a different directory`;
}

export const pattern: TestPattern = {
description:
"#JsSdkTest-11 Should throw an error when the output directory contains forbidden characters",
input: {
command: CREATE_PLUGIN_COMMAND,
outputDir: outputDir,
questionsInput: [
{
question: m("Q_NameEn"),
answer: "test11-name",
},
{
question: m("Q_DescriptionEn"),
answer: "test11-description",
},
{
question: m("Q_SupportJa"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_SupportZh"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_WebsiteUrlEn"),
answer: DEFAULT_ANSWER,
},
{
question: m("Q_MobileSupport"),
answer: ANSWER_NO,
},
{
question: m("Q_EnablePluginUploader"),
answer: ANSWER_NO,
},
],
},
expected: {
failure: {
stderr: expectedStderr,
},
},
};
11 changes: 8 additions & 3 deletions packages/create-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ ${m("developerSite")}
`);
})
.catch((error: Error) => {
rimraf(outputDir, { glob: true }).then(() => {
printError(m("Error_cannotCreatePlugin"), error.message);
});
rimraf(outputDir, { glob: true })
.then(() => {
printError(m("Error_cannotCreatePlugin"), error.message);
})
.finally(() => {
// eslint-disable-next-line no-process-exit
process.exit(1);
});
});
};

Expand Down

0 comments on commit 0186ba8

Please sign in to comment.