Skip to content

Commit

Permalink
Adopt error handling / add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed May 29, 2020
1 parent ff41ef8 commit bb8e1ef
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/ui5Framework/AbstractResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ class AbstractResolver {
const versions = await this.fetchAllVersions({ui5HomeDir, cwd});
const resolvedVersion = semver.maxSatisfying(versions, spec);
if (!resolvedVersion) {
if (this.name === "Sapui5Resolver" && semver.valid(spec) && semver.lt(spec, "1.76.0")) {
throw new Error(`Could not resolve framework version ${version}. ` +
`Note that SAPUI5 framework libraries can only be consumed by the UI5 Tooling ` +
`starting with SAPUI5 v1.76.0`);
} else
if (this.name === "Openui5Resolver" && semver.valid(spec) && semver.lt(spec, "1.52.5")) {
throw new Error(`Could not resolve framework version ${version}. ` +
`Note that OpenUI5 framework libraries can only be consumed by the UI5 Tooling ` +
`starting with OpenUI5 v1.52.5`);
if (semver.valid(spec)) {
if (this.name === "Sapui5Resolver" && semver.lt(spec, "1.76.0")) {
throw new Error(`Could not resolve framework version ${version}. ` +
`Note that SAPUI5 framework libraries can only be consumed by the UI5 Tooling ` +
`starting with SAPUI5 v1.76.0`);
} else if (this.name === "Openui5Resolver" && semver.lt(spec, "1.52.5")) {
throw new Error(`Could not resolve framework version ${version}. ` +
`Note that OpenUI5 framework libraries can only be consumed by the UI5 Tooling ` +
`starting with OpenUI5 v1.52.5`);
}
}
throw new Error(`Could not resolve framework version ${version}`);
}
Expand Down
34 changes: 34 additions & 0 deletions test/lib/ui5framework/AbstractResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,40 @@ test.serial(
t.is(error.message, `Could not resolve framework version latest`);
});

test.serial(
"AbstractResolver: Static resolveVersion throws error when OpenUI5 version range cannot be resolved", async (t) => {
class Openui5Resolver extends AbstractResolver {
static async fetchAllVersions() {}
}

sinon.stub(Openui5Resolver, "fetchAllVersions")
.returns([]);

const error = await t.throwsAsync(Openui5Resolver.resolveVersion("1.99", {
cwd: "/cwd",
ui5HomeDir: "/ui5HomeDir"
}));

t.is(error.message, `Could not resolve framework version 1.99`);
});

test.serial(
"AbstractResolver: Static resolveVersion throws error when SAPUI5 version range cannot be resolved", async (t) => {
class Sapui5Resolver extends AbstractResolver {
static async fetchAllVersions() {}
}

sinon.stub(Sapui5Resolver, "fetchAllVersions")
.returns([]);

const error = await t.throwsAsync(Sapui5Resolver.resolveVersion("1.99", {
cwd: "/cwd",
ui5HomeDir: "/ui5HomeDir"
}));

t.is(error.message, `Could not resolve framework version 1.99`);
});

test.serial("AbstractResolver: SEMVER_VERSION_REGEXP should be aligned with JSON schema", async (t) => {
const projectSchema = require("../../../lib/validation/schema/specVersion/2.0/kind/project.json");
const schemaPattern = projectSchema.definitions.framework.properties.version.pattern;
Expand Down

0 comments on commit bb8e1ef

Please sign in to comment.