-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: testing around current branch logic
- Loading branch information
lshadler
committed
Oct 25, 2021
1 parent
f1c3f4a
commit d0c97b7
Showing
2 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { execSync } from "child_process"; | ||
import { CiEnv } from "env-ci"; | ||
import { getCurrentBranch } from "../auto"; | ||
|
||
jest.mock('child_process') | ||
|
||
describe('getCurrentBranch', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('when isPr', () => { | ||
it('returns pr branch from env ci when valid', () => { | ||
const env: Partial<CiEnv> = { | ||
isPr: true, | ||
prBranch: 'my-pr-branch' | ||
} | ||
expect(getCurrentBranch(env)).toBe('my-pr-branch') | ||
}); | ||
|
||
it('tries git command when PR is invalid', () => { | ||
const env: Partial<CiEnv> = { | ||
isPr: true, | ||
prBranch: 'undefined' | ||
} | ||
|
||
getCurrentBranch(env); | ||
|
||
expect(execSync).toHaveBeenCalledWith("git symbolic-ref --short HEAD", { | ||
encoding: "utf8", | ||
stdio: "ignore", | ||
}) | ||
}); | ||
}) | ||
|
||
describe('when not isPr', () => { | ||
|
||
it('returns pr branch from env ci when valid', () => { | ||
const env: Partial<CiEnv> = { | ||
isPr: false, | ||
prBranch: 'my-pr-branch', | ||
branch: 'my-release-branch' | ||
} | ||
|
||
expect(getCurrentBranch(env)).toBe('my-release-branch'); | ||
|
||
expect(execSync).not.toHaveBeenCalled() | ||
}); | ||
|
||
it('tries git command when branch name is invalid', () => { | ||
const env: Partial<CiEnv> = { | ||
isPr: false, | ||
prBranch: 'my-pr-branch', | ||
branch: undefined | ||
} | ||
getCurrentBranch(env); | ||
|
||
expect(execSync).toHaveBeenCalledWith("git symbolic-ref --short HEAD", { | ||
encoding: "utf8", | ||
stdio: "ignore", | ||
}) | ||
}); | ||
}) | ||
}) |
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