-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
c5b5be5
commit 5b023e2
Showing
4 changed files
with
113 additions
and
40 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,13 @@ | ||
import * as main from "../src/main"; | ||
|
||
// Mock the action's entrypoint | ||
const runMock = jest.spyOn(main, "run").mockImplementation(); | ||
|
||
describe("index", () => { | ||
it("calls run when imported", async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
require("../src/index"); | ||
|
||
expect(runMock).toHaveBeenCalled(); | ||
}); | ||
}); |
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,48 @@ | ||
import * as core from "@actions/core"; | ||
import * as main from "../src/main"; | ||
|
||
// Mock the action's main function | ||
const runMock = jest.spyOn(main, "run"); | ||
|
||
// Mock the GitHub Actions core library | ||
let errorMock: jest.SpyInstance; | ||
let getInputMock: jest.SpyInstance; | ||
let getMultilineInput: jest.SpyInstance; | ||
let setFailedMock: jest.SpyInstance; | ||
|
||
describe("action", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
errorMock = jest.spyOn(core, "error").mockImplementation(); | ||
getInputMock = jest.spyOn(core, "getInput").mockImplementation(); | ||
getMultilineInput = jest.spyOn(core, "getMultilineInput").mockImplementation(); | ||
setFailedMock = jest.spyOn(core, "setFailed").mockImplementation(); | ||
}); | ||
|
||
it("sets a failed status", async () => { | ||
getMultilineInput.mockImplementation((name: string): string[] => { | ||
switch (name) { | ||
default: | ||
return []; | ||
} | ||
}); | ||
|
||
getInputMock.mockImplementation((name: string): string => { | ||
switch (name) { | ||
default: | ||
return ""; | ||
} | ||
}); | ||
|
||
await main.run(); | ||
expect(runMock).toHaveReturned(); | ||
|
||
// Verify that all of the core library functions were called correctly | ||
expect(setFailedMock).toHaveBeenNthCalledWith( | ||
1, | ||
"input provided for identity_url not in expected format", | ||
); | ||
expect(errorMock).not.toHaveBeenCalled(); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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