-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allows multiple selections for the comment-on option
- Loading branch information
1 parent
a7a72ad
commit e5edf3b
Showing
7 changed files
with
192 additions
and
53 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,73 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
import * as core from "@actions/core"; | ||
import { getCommentOn, type CommentOn } from "./getCommentOn"; | ||
|
||
vi.mock("@actions/core"); | ||
|
||
describe("getCommentOn()", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("returns the default value ['pr'] if no valid values are provided", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("invalid1, invalid2"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'No valid options for comment-on found. Falling back to default value "pr".', | ||
); | ||
}); | ||
|
||
it("logs invalid values", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, invalid, commit"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'Invalid options for comment-on: invalid. Valid options are "pr" and "commit".', | ||
); | ||
}); | ||
|
||
it("returns valid values correctly", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, commit"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("trims whitespace from the input", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, commit"); | ||
|
||
const result = getCommentOn(); | ||
|
||
expect(result).toEqual(["pr", "commit"]); | ||
|
||
expect(core.warning).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("returns valid values and logs invalid values", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue( | ||
"pr, invalid, commit, anotherInvalid", | ||
); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'Invalid options for comment-on: invalid, anotherInvalid. Valid options are "pr" and "commit".', | ||
); | ||
}); | ||
|
||
it("for value 'none', returns empty array", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("none"); | ||
|
||
const result = getCommentOn(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.
e5edf3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
⬇️ -1.63%
⬇️ -1.63%
⬆️ +0.95%
⬆️ +0.77%
File Coverage