-
Notifications
You must be signed in to change notification settings - Fork 203
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 #1636 from intuit/pr-check
improve pr-check usage + don't fail on runs in CI base branch
- Loading branch information
Showing
4 changed files
with
97 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import envCi from "env-ci"; | ||
import { dummyLog } from "../utils/logger"; | ||
|
||
jest.mock("env-ci"); | ||
|
||
const envSpy = envCi as jest.Mock; | ||
envSpy.mockImplementation(() => ({ | ||
isCi: true, | ||
branch: "master", | ||
})); | ||
|
||
import { Auto } from "../auto"; | ||
|
||
const defaults = { | ||
owner: "foo", | ||
repo: "bar", | ||
}; | ||
|
||
jest.mock("@octokit/rest", () => { | ||
const Octokit = class MockOctokit { | ||
static plugin = () => Octokit; | ||
|
||
authenticate = () => undefined; | ||
|
||
search = { | ||
issuesAndPullRequests: () => ({ data: { items: [] } }), | ||
}; | ||
|
||
repos = { | ||
get: jest.fn().mockReturnValue({}), | ||
}; | ||
|
||
hook = { | ||
error: () => undefined, | ||
}; | ||
}; | ||
|
||
return { Octokit }; | ||
}); | ||
|
||
describe("Auto", () => { | ||
describe("pr-check", () => { | ||
jest.setTimeout(10 * 1000); | ||
let createStatus: jest.Mock; | ||
|
||
beforeEach(() => { | ||
createStatus = jest.fn(); | ||
}); | ||
|
||
const required = { | ||
url: "https://google.com", | ||
}; | ||
|
||
test("should exit successfully if ran from master + CI", async () => { | ||
const auto = new Auto(defaults); | ||
const exit = jest.fn(); | ||
|
||
envSpy.mockImplementationOnce(() => ({ | ||
isCi: true, | ||
branch: "master", | ||
})); | ||
|
||
// @ts-ignore | ||
process.exit = exit; | ||
auto.logger = dummyLog(); | ||
await auto.loadConfig(); | ||
auto.git!.createStatus = createStatus; | ||
|
||
await auto.prCheck({ ...required }); | ||
expect(exit).toHaveBeenCalledWith(0); | ||
}); | ||
}); | ||
}); |
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