Skip to content

Commit

Permalink
[FIX] ui5 init: Improve error message (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 authored Oct 30, 2023
1 parent 5fb183d commit 07e68b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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

0 comments on commit 07e68b0

Please sign in to comment.