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

[FIX] ui5 init: Improve error message #661

Merged
merged 2 commits into from
Oct 30, 2023
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
5 changes: 4 additions & 1 deletion lib/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ function getProjectType(hasWebapp, hasSrc, hasTest) {

let message = `Could not detect project type: ${errorReason}`;
message += "Applications should only have a 'webapp' folder.\n";
message += "Libraries should only have a 'src' and (optional) 'test' folder.";
message += "Libraries should only have an 'src' and (optional) 'test' folder.";
message += "\n\n";
message += "If you are about to start a new project, please refer to:\n";
message += "https://sap.github.io/ui5-tooling/v3/pages/GettingStarted/#starting-a-new-project";
throw new Error(message);
}

Expand Down
21 changes: 11 additions & 10 deletions test/lib/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,50 @@ test("Init for library", async (t) => {
});
});

const GENERAL_ERROR_MESSAGE = `Applications should only have a 'webapp' folder.
Libraries should only have an 'src' and (optional) 'test' folder.

If you are about to start a new project, please refer to:
https://sap.github.io/ui5-tooling/v3/pages/GettingStarted/#starting-a-new-project`;

test("Init for invalid project (Found 'webapp', 'src' and 'test' folders)", async (t) => {
await t.throwsAsync(init({
cwd: getFixturePath("invalid-webapp-src-test")
}), {message:
"Could not detect project type: Found 'webapp', 'src' and 'test' folders.\n" +
"Applications should only have a 'webapp' folder.\n" +
"Libraries should only have a 'src' and (optional) 'test' folder."});
GENERAL_ERROR_MESSAGE});
});

test("Init for invalid project (Found 'webapp' and 'src' folders)", async (t) => {
await t.throwsAsync(init({
cwd: getFixturePath("invalid-webapp-src")
}), {message:
"Could not detect project type: Found 'webapp' and 'src' folders.\n" +
"Applications should only have a 'webapp' folder.\n" +
"Libraries should only have a 'src' and (optional) 'test' folder."});
GENERAL_ERROR_MESSAGE});
});

test("Init for invalid project (Found 'webapp' and 'test' folders)", async (t) => {
await t.throwsAsync(init({
cwd: getFixturePath("invalid-webapp-test")
}), {message:
"Could not detect project type: Found 'webapp' and 'test' folders.\n" +
"Applications should only have a 'webapp' folder.\n" +
"Libraries should only have a 'src' and (optional) 'test' folder."});
GENERAL_ERROR_MESSAGE});
});

test("Init for invalid project (Found 'test' folder but no 'src' folder)", async (t) => {
await t.throwsAsync(init({
cwd: getFixturePath("invalid-test")
}), {message:
"Could not detect project type: Found 'test' folder but no 'src' folder.\n" +
"Applications should only have a 'webapp' folder.\n" +
"Libraries should only have a 'src' and (optional) 'test' folder."});
GENERAL_ERROR_MESSAGE});
});

test("Init for invalid project (Could not find 'webapp' or 'src' / 'test' folders)", async (t) => {
await t.throwsAsync(init({
cwd: getFixturePath("invalid")
}), {message:
"Could not detect project type: Could not find 'webapp' or 'src' / 'test' folders.\n" +
"Applications should only have a 'webapp' folder.\n" +
"Libraries should only have a 'src' and (optional) 'test' folder."});
GENERAL_ERROR_MESSAGE});
});

test("Init for invalid project (No package.json)", async (t) => {
Expand Down
Loading