Skip to content

Commit

Permalink
test: add test for failing command
Browse files Browse the repository at this point in the history
  • Loading branch information
motiz88 committed May 20, 2018
1 parent 25694e2 commit ee81abf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"babel-preset-stage-0": "^6.24.1",
"codecov": "^2.2.0",
"if-env": "^1.0.0",
"invert-promise": "^1.0.1",
"jest": "^20.0.0",
"mock-bin": "^2.0.0",
"mock-git": "^2.0.0",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`git-exec-and-restage no command, no args and no files staged 1`] = `[Error: Usage: git-exec-and-restage <command> [...command-args --] [...files]]`;
exports[`git-exec-and-restage throws when command fails 1`] = `"Error running command: Exited with status 1"`;
exports[`git-exec-and-restage with command and arguments, no files 1`] = `
Array [
"git diff-index --cached --name-only --diff-filter=ACDMRTUXB HEAD --",
Expand Down
7 changes: 7 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gitExecAndRestage from "../";
import TestEnvironment from "TestEnvironment";
import path from "path";
import flip from "invert-promise";

describe("git-exec-and-restage", () => {
const env = new TestEnvironment();
Expand All @@ -14,6 +15,12 @@ describe("git-exec-and-restage", () => {
await gitExecAndRestage(["prettier"]);
expect(await env.log).toMatchSnapshot();
});
it("throws when command fails", async () => {
await env.mockBinError("prettier");
const error = await flip(gitExecAndRestage(["prettier"]));
expect(error.__isExpectedError).toBe(true);
expect(error.message).toMatchSnapshot();
});
it("with command and arguments, no files", async () => {
await env.mockBin("prettier");
await gitExecAndRestage(["prettier", "--write", "--"]);
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,10 @@ invert-kv@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"

invert-promise@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/invert-promise/-/invert-promise-1.0.1.tgz#22d8b5f3cef87633743f86a96b3885dcdfd91fa2"

is-arrayish@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
Expand Down

0 comments on commit ee81abf

Please sign in to comment.