Skip to content

Commit

Permalink
[FIX] ui5 use <framework> should default to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Mar 1, 2021
1 parent 21fcc74 commit cda4b2c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/cli/commands/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ useCommand.builder = function(cli) {
.positional("framework-info", {
describe: "Framework name, version or both (name@version).\n" +
"Name can be \"SAPUI5\" or \"OpenUI5\" (case-insensitive).\n" +
"Version can be \"latest\", \"1.xx\" or \"1.xx.x\".",
"Version can be \"latest\" (default), \"1.xx\" or \"1.xx.x\".",
type: "string"
})
.example("$0 use sapui5@latest", "Use SAPUI5 in the latest available version")
.example("$0 use openui5@1.76", "Use OpenUI5 in the latest available 1.76 patch version")
.example("$0 use latest", "Use the latest available version of the configured framework")
.example("$0 use openui5", "Use OpenUI5 without a version (or use existing version)");
.example("$0 use openui5", "Use OpenUI5 in the latest available version");
};

function parseFrameworkInfo(frameworkInfo) {
Expand All @@ -32,9 +32,10 @@ function parseFrameworkInfo(frameworkInfo) {
throw new Error("Invalid framework info: " + frameworkInfo);
}
if (["sapui5", "openui5"].includes(nameOrVersion.toLowerCase())) {
// Framework name without version uses "latest", similar to npm install behavior
return {
name: nameOrVersion,
version: null
version: "latest"
};
} else {
return {
Expand Down
62 changes: 56 additions & 6 deletions test/lib/cli/commands/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ async function assertFailingYamlUpdateUseHandler(t, {argv, expectedMessage}) {
t.is(frameworkUseStub.callCount, 1, "Use function should be called once");
}

test.beforeEach((t) => {
t.context.consoleLogStub = sinon.stub(console, "log");
});

test.afterEach.always(() => {
mock.stopAll();
sinon.restore();
Expand Down Expand Up @@ -138,32 +142,32 @@ test.serial("Accepts framework name and version (OpenUI5@latest)", async (t) =>
});
});

test.serial("Accepts framework name (SAPUI5)", async (t) => {
test.serial("Accepts framework name and uses latest (SAPUI5)", async (t) => {
await assertUseHandler(t, {
argv: {"framework-info": "SAPUI5"},
expectedFrameworkOptions: {
name: "SAPUI5",
version: null
version: "latest"
}
});
});

test.serial("Accepts framework name (sapui5)", async (t) => {
test.serial("Accepts framework name and uses latest (sapui5)", async (t) => {
await assertUseHandler(t, {
argv: {"framework-info": "sapui5"},
expectedFrameworkOptions: {
name: "sapui5",
version: null
version: "latest"
}
});
});

test.serial("Accepts framework name (OpenUI5)", async (t) => {
test.serial("Accepts framework name and uses latest (OpenUI5)", async (t) => {
await assertUseHandler(t, {
argv: {"framework-info": "OpenUI5"},
expectedFrameworkOptions: {
name: "OpenUI5",
version: null
version: "latest"
}
});
});
Expand Down Expand Up @@ -246,3 +250,49 @@ test.serial("Rejects when YAML could not be updated (with config path)", async (
expectedMessage: "Internal error while updating config at /path/to/ui5.yaml to SAPUI5 version 1.76.0"
});
});

test.serial("Logs framework name, version and default config path when updating config", async (t) => {
const frameworkUseStub = sinon.stub().resolves({
usedFramework: "SAPUI5",
usedVersion: "1.76.0",
yamlUpdated: true
});
mock("../../../../lib/framework/use", frameworkUseStub);

await useCommand.handler({"framework-info": "SAPUI5@1.76.0"});

const expectedConsoleLog = [
"Updated configuration written to ui5.yaml",
"This project is now using SAPUI5 version 1.76.0"
];

t.is(t.context.consoleLogStub.callCount, expectedConsoleLog.length,
"console.log should be called " + expectedConsoleLog.length + " times");
expectedConsoleLog.forEach((expectedLog, i) => {
t.deepEqual(t.context.consoleLogStub.getCall(i).args, [expectedLog],
"console.log should be called with expected string on call index " + i);
});
});

test.serial("Logs framework name, version and custom config path when updating config", async (t) => {
const frameworkUseStub = sinon.stub().resolves({
usedFramework: "SAPUI5",
usedVersion: "1.76.0",
yamlUpdated: true
});
mock("../../../../lib/framework/use", frameworkUseStub);

await useCommand.handler({"framework-info": "SAPUI5@1.76.0", "config": "/path/to/ui5.yaml"});

const expectedConsoleLog = [
"Updated configuration written to /path/to/ui5.yaml",
"This project is now using SAPUI5 version 1.76.0"
];

t.is(t.context.consoleLogStub.callCount, expectedConsoleLog.length,
"console.log should be called " + expectedConsoleLog.length + " times");
expectedConsoleLog.forEach((expectedLog, i) => {
t.deepEqual(t.context.consoleLogStub.getCall(i).args, [expectedLog],
"console.log should be called with expected string on call index " + i);
});
});

0 comments on commit cda4b2c

Please sign in to comment.