-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from korthout/test-git
Test git module
- Loading branch information
Showing
5 changed files
with
134 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Git, GitRefNotFoundError } from "../git"; | ||
import { execa } from "execa"; | ||
|
||
const git = new Git(execa); | ||
let response = { exitCode: 0, stdout: "" }; | ||
|
||
jest.mock("execa", () => ({ | ||
execa: jest.fn(() => response), | ||
})); | ||
|
||
describe("git.fetch", () => { | ||
describe("throws GitRefNotFoundError", () => { | ||
it("when fetching an unknown ref, i.e. exit code 128", async () => { | ||
response.exitCode = 128; | ||
expect.assertions(3); | ||
await git.fetch("unknown", "", 1).catch((error) => { | ||
expect(error).toBeInstanceOf(GitRefNotFoundError); | ||
expect(error).toHaveProperty( | ||
"message", | ||
"Expected to fetch 'unknown', but couldn't find it", | ||
); | ||
expect(error).toHaveProperty("ref", "unknown"); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("throws Error", () => { | ||
it("when failing with an unexpected non-zero exit code", async () => { | ||
response.exitCode = 1; | ||
await expect(git.fetch("unknown", "", 1)).rejects.toThrowError( | ||
`'git fetch origin unknown' failed with exit code 1`, | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("git.cherryPick", () => { | ||
describe("throws Error", () => { | ||
it("when failing with an unexpected non-zero exit code", async () => { | ||
response.exitCode = 1; | ||
await expect(git.cherryPick(["unknown"], "")).rejects.toThrowError( | ||
`'git cherry-pick -x unknown' failed with exit code 1`, | ||
); | ||
}); | ||
}); | ||
}); |