UNPKG

1.39 kBPlain TextView Raw
1import * as fs from "fs-extra";
2import { setupFixture } from "backfill-utils-test";
3
4import { createBuildCommand } from "../commandRunner";
5
6describe("createBuildCommand", () => {
7 it("runs a command successfully", async () => {
8 const buildCommand = createBuildCommand(["echo foo"], false, "");
9
10 const buildResult = await buildCommand();
11
12 if (buildResult) {
13 expect(buildResult.stdout).toEqual("foo");
14 }
15 });
16
17 it("resolves if no command can be found", async () => {
18 const buildCommand = createBuildCommand([""], false, "");
19
20 await expect(buildCommand()).rejects.toThrow("Command not provided");
21 });
22
23 it("prints the error command and throws if it fails", async () => {
24 const buildCommand = createBuildCommand(["somecommand"], false, "");
25
26 try {
27 await buildCommand();
28 } catch (err) {
29 expect(err.stderr).toContain("somecommand");
30 expect(err.code).not.toEqual(0);
31 }
32 });
33
34 it("clears the output folder", async () => {
35 await setupFixture("pre-built");
36 const buildCommand = createBuildCommand(["echo foo"], true, "lib");
37
38 const index_js_ExistsBeforeBuild = await fs.pathExists("lib/index.js");
39 await buildCommand();
40 const index_js_ExistsAfterBuild = await fs.pathExists("lib/index.js");
41
42 expect(index_js_ExistsBeforeBuild).toEqual(true);
43 expect(index_js_ExistsAfterBuild).toEqual(false);
44 });
45});