Skip to content

Commit

Permalink
Merge pull request trufflesuite#2110 from trufflesuite/box/command
Browse files Browse the repository at this point in the history
Internal improvement: Tidy up unbox command & add some coverage
  • Loading branch information
CruzMolina authored Jun 19, 2019
2 parents ffde3b5 + f5f533a commit 3ea1fef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/truffle-core/lib/commands/unbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function normalizeURL(
url = `${url}-box`;
} else {
const index = url.indexOf("#");
url = url.substr(0, index) + "-box" + url.substr(index);
url = `${url.substr(0, index)}-box${url.substr(index)}`;
}
}
return `https://github.com/truffle-box/${url}`;
Expand All @@ -44,7 +44,7 @@ function normalizeURL(
function formatCommands(commands) {
const names = Object.keys(commands);

const maxLength = Math.max.apply(null, names.map(name => name.length));
const maxLength = Math.max.apply(null, names.map(({ length }) => length));

return names.map(name => {
const spacing = Array(maxLength - name.length + 1).join(" ");
Expand Down Expand Up @@ -126,19 +126,15 @@ const command = {
const unboxOptions = Object.assign({}, options, { logger: config.logger });

Box.unbox(url, destination, unboxOptions)
.then(boxConfig => {
config.logger.log("\nUnbox successful. Sweet!" + OS.EOL);
.then(({ commands }) => {
config.logger.log(`\nUnbox successful. Sweet!${OS.EOL}`);

const commandMessages = formatCommands(boxConfig.commands);
if (commandMessages.length > 0) config.logger.log("Commands:" + OS.EOL);
const commandMessages = formatCommands(commands);
if (commandMessages.length > 0) config.logger.log(`Commands:${OS.EOL}`);

commandMessages.forEach(message => config.logger.log(message));
config.logger.log("");

if (boxConfig.epilogue) {
config.logger.log(boxConfig.epilogue.replace("\n", OS.EOL));
}

done();
})
.catch(done);
Expand Down
20 changes: 20 additions & 0 deletions packages/truffle/test/scenarios/commands/unbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ describe("truffle unbox [ @standalone ]", () => {
}).timeout(20000);
});

describe("official truffle-box", () => {
it("unboxes successfully", done => {
CommandRunner.run("unbox bare-box", config, () => {
const output = logger.contents();
assert(output.includes("Unbox successful."));
done();
});
}).timeout(20000);
});

describe("official truffle box + branch", () => {
it("unboxes successfully", done => {
CommandRunner.run("unbox bare#truffle-test-branch", config, () => {
Expand Down Expand Up @@ -288,4 +298,14 @@ describe("truffle unbox [ @standalone ]", () => {
});
});
});
describe("when truffle-box.json contains commands", () => {
it("unboxes successfully and outputs commands", done => {
CommandRunner.run("unbox bare", config, () => {
const output = logger.contents();
assert(output.includes("Unbox successful."));
assert(output.includes("Test contracts:"));
done();
});
}).timeout(20000);
});
});

0 comments on commit 3ea1fef

Please sign in to comment.