Skip to content

Commit ccee4c6

Browse files
committed
Add tests for CODE_SCANNING_REF
1 parent 899bf9c commit ccee4c6

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

lib/actions-util.test.js

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/actions-util.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,33 @@ test("getRef() returns ref provided as an input and ignores current HEAD", async
8888
});
8989
});
9090

91+
test("getRef() returns CODE_SCANNING_REF as a fallback for GITHUB_REF", async (t) => {
92+
await withTmpDir(async (tmpDir: string) => {
93+
setupActionsVars(tmpDir, tmpDir);
94+
const expectedRef = "refs/pull/1/HEAD";
95+
const currentSha = "a".repeat(40);
96+
process.env["CODE_SCANNING_REF"] = expectedRef;
97+
process.env["GITHUB_SHA"] = currentSha;
98+
99+
const actualRef = await actionsutil.getRef();
100+
t.deepEqual(actualRef, expectedRef);
101+
});
102+
});
103+
104+
test("getRef() returns GITHUB_REF over CODE_SCANNING_REF if both are provided", async (t) => {
105+
await withTmpDir(async (tmpDir: string) => {
106+
setupActionsVars(tmpDir, tmpDir);
107+
const expectedRef = "refs/pull/1/merge";
108+
const currentSha = "a".repeat(40);
109+
process.env["CODE_SCANNING_REF"] = "refs/pull/1/HEAD";
110+
process.env["GITHUB_REF"] = expectedRef;
111+
process.env["GITHUB_SHA"] = currentSha;
112+
113+
const actualRef = await actionsutil.getRef();
114+
t.deepEqual(actualRef, expectedRef);
115+
});
116+
});
117+
91118
test("getRef() throws an error if only `ref` is provided as an input", async (t) => {
92119
await withTmpDir(async (tmpDir: string) => {
93120
setupActionsVars(tmpDir, tmpDir);

0 commit comments

Comments
 (0)