generated from CIFriends/typescript-action-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1afec2
commit fb5a7b2
Showing
1 changed file
with
39 additions
and
0 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,39 @@ | ||
import * as core from "@actions/core"; | ||
import { getFilesByExtension } from "../src/utils/ExtensionFilter"; | ||
import { processFiles } from "../src/utils/FileProcessor"; | ||
import { run } from "../src/main"; | ||
import { InputParams } from "../src/utils/VariableManager"; | ||
|
||
jest.mock("@actions/core"); | ||
jest.mock("../src/utils/ExtensionFilter"); | ||
jest.mock("../src/utils/FileProcessor"); | ||
jest.mock("path"); | ||
|
||
const mockedCore = core as jest.Mocked<typeof core>; | ||
const mockedGetFilesByExtension = getFilesByExtension as jest.MockedFunction<typeof getFilesByExtension>; | ||
const mockedProcessFiles = processFiles as jest.MockedFunction<typeof processFiles>; | ||
const inputParams: InputParams = { | ||
rootDir: "/root", | ||
extension: ".ts", | ||
envVars: new Map(), | ||
ignoredDir: [], | ||
ignoredVars: [], | ||
includeSubDir: true, | ||
encodings: "utf8" | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("run should process files when files are found", () => { | ||
mockedGetFilesByExtension.mockReturnValue(["file1.ts", "file2.ts"]); | ||
run(inputParams); | ||
expect(mockedProcessFiles).toHaveBeenCalled(); | ||
}); | ||
|
||
test("run should warn when no files are found", () => { | ||
mockedGetFilesByExtension.mockReturnValue([]); | ||
run(inputParams); | ||
expect(mockedCore.warning).toHaveBeenCalledWith(`No files found with extension ${inputParams.extension} in ${inputParams.rootDir}`); | ||
}); |