/
_gitlab.test.ts
47 lines (40 loc) · 1.35 KB
/
_gitlab.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { GitLabCI } from "../GitLabCI"
import { getCISourceForEnv } from "../../get_ci_source"
const correctEnv = {
GITLAB_CI: "true",
CI_MERGE_REQUEST_IID: "27117",
CI_PROJECT_PATH: "gitlab-org/gitlab-foss",
}
describe("being found when looking for CI", () => {
it("finds GitLab with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(GitLabCI)
})
})
describe(".isCI", () => {
it("validates when all GitLab environment vars are set", async () => {
const result = new GitLabCI(correctEnv)
expect(result.isCI).toBeTruthy()
})
it("does not validate without env", async () => {
const result = new GitLabCI({})
expect(result.isCI).toBeFalsy()
})
})
describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const result = new GitLabCI(correctEnv)
expect(result.pullRequestID).toEqual("27117")
})
})
describe(".repoSlug", () => {
it("derives it from 'CI_PROJECT_PATH' env var", () => {
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss")
})
it("derives it form 'CI_MERGE_REQUEST_PROJECT_PATH' env var if set", () => {
correctEnv["CI_MERGE_REQUEST_PROJECT_PATH"] = "gitlab-org/release-tools"
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/release-tools")
})
})