truffle
Version:
Truffle - Simple development framework for Ethereum
89 lines (77 loc) • 2.61 kB
JavaScript
const assert = require("assert");
const CommandRunner = require("../commandRunner");
const MemoryLogger = require("../MemoryLogger");
const sandbox = require("../sandbox");
const path = require("path");
describe("truffle build [ @standalone ]", () => {
const logger = new MemoryLogger();
let config, project, cleanupSandboxDir;
describe("when there is no build script in config", () => {
beforeEach("set up sandbox", async function () {
project = path.join(
__dirname,
"../../sources/build/projectWithoutBuildScript"
);
({ config, cleanupSandboxDir } = await sandbox.create(project));
config.logger = logger;
});
afterEach(function () {
cleanupSandboxDir();
});
it("should not error", async () => {
try {
await CommandRunner.run("build", config);
} catch (error) {
assert(false, "An error should not have occurred.");
}
}).timeout(30000);
it("whines about having no build config", async () => {
await CommandRunner.run("build", config);
const output = logger.contents();
assert(output.includes("No build configuration found."));
}).timeout(30000);
});
describe("when there is a proper build config", () => {
beforeEach("set up sandbox", async function () {
project = path.join(
__dirname,
"../../sources/build/projectWithBuildScript"
);
({ config, cleanupSandboxDir } = await sandbox.create(project));
config.logger = logger;
});
afterEach(function () {
cleanupSandboxDir();
});
it("runs the build script", async function () {
await CommandRunner.run("build", config);
const output = logger.contents();
assert(output.includes("'this is the build script'"));
}).timeout(30000);
});
describe("when there is an object in the build config", () => {
beforeEach("set up sandbox", async function () {
project = path.join(
__dirname,
"../../sources/build/projectWithObjectInBuildScript"
);
({ config, cleanupSandboxDir } = await sandbox.create(project));
config.logger = logger;
});
afterEach(function () {
cleanupSandboxDir();
});
it("tells the user it shouldn't use an object", async function () {
try {
await CommandRunner.run("build", config);
} catch (error) {
const output = logger.contents();
assert(
output.includes(
"Build configuration can no longer be specified as an object."
)
);
}
}).timeout(20000);
});
});