Skip to content

Commit 3a79ba2

Browse files
committed
[INTERNAL] createWorkspace: Remove dead code and test uncovered paths
1 parent 380a5ac commit 3a79ba2

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

lib/graph/helpers/createWorkspace.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export default async function createWorkspace({
3737
filePath = path.join(cwd, configPath);
3838
}
3939
try {
40-
const workspaceConfigs =
41-
await readWorkspaceConfigFile(filePath, );
40+
const workspaceConfigs = await readWorkspaceConfigFile(filePath);
4241
const configuration = workspaceConfigs.find((config) => {
4342
return config.metadata.name === name;
4443
});
@@ -69,7 +68,7 @@ export default async function createWorkspace({
6968
}
7069
}
7170

72-
async function readWorkspaceConfigFile(filePath, throwIfMissing) {
71+
async function readWorkspaceConfigFile(filePath) {
7372
const {
7473
default: fs
7574
} = await import("graceful-fs");
@@ -92,13 +91,7 @@ async function readWorkspaceConfigFile(filePath, throwIfMissing) {
9291
filename: filePath,
9392
});
9493
} catch (err) {
95-
if (err.name === "YAMLException") {
96-
throw new Error(`Failed to parse workspace configuration at ` +
97-
`${filePath}\nError: ${err.message}`);
98-
} else {
99-
throw new Error(
100-
`Failed to parse workspace configuration at ${filePath}: ${err.message}`);
101-
}
94+
throw new Error(`Failed to parse workspace configuration at ${filePath}\nError: ${err.message}`);
10295
}
10396

10497
if (!configs || !configs.length) {

test/lib/graph/helpers/createWorkspace.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ test("createWorkspace: Using invalid object", async (t) => {
117117
"Threw with validation error");
118118
});
119119

120+
test("createWorkspace: Using name and object with different workspace name", async (t) => {
121+
const {createWorkspace} = t.context;
122+
123+
const err = await t.throwsAsync(createWorkspace({
124+
cwd: "cwd",
125+
name: "my-workspace",
126+
configObject: {
127+
metadata: {
128+
name: "my-other-workspace"
129+
},
130+
dependencyManagement: {
131+
resolutions: [{
132+
path: "resolution/path"
133+
}]
134+
}
135+
}
136+
}));
137+
t.is(err.message,
138+
`The provided workspace name 'my-workspace' does not match ` +
139+
`the provided workspace configuration 'my-other-workspace'`,
140+
"Threw with validation error");
141+
});
142+
120143
test("createWorkspace: Using file", async (t) => {
121144
const {createWorkspace, MockWorkspace, workspaceConstructorStub} = t.context;
122145

@@ -171,6 +194,20 @@ test("createWorkspace: Using missing file", async (t) => {
171194
t.is(workspaceConstructorStub.callCount, 0, "Workspace constructor did not get called");
172195
});
173196

197+
test("createWorkspace: Missing default workspace in file", async (t) => {
198+
const {createWorkspace, workspaceConstructorStub} = t.context;
199+
200+
const res = await createWorkspace({
201+
cwd: path.join(fixturesPath, "library.h"),
202+
name: "default",
203+
configPath: path.join(fixturesPath, "library.h", "custom-ui5-workspace.yaml")
204+
});
205+
206+
t.is(res, null, "Returned no workspace");
207+
208+
t.is(workspaceConstructorStub.callCount, 0, "Workspace constructor did not get called");
209+
});
210+
174211
test("createWorkspace: Using missing file and non-default name", async (t) => {
175212
const {createWorkspace, workspaceConstructorStub} = t.context;
176213

0 commit comments

Comments
 (0)