From fb5a7b202e1ce0ca6cb7e9e6d2663e8d9b462617 Mon Sep 17 00:00:00 2001 From: "Breno A." Date: Fri, 10 May 2024 00:51:49 -0300 Subject: [PATCH] tests: add main test --- __tests__/main.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 __tests__/main.test.ts diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts new file mode 100644 index 0000000..86abc9c --- /dev/null +++ b/__tests__/main.test.ts @@ -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; +const mockedGetFilesByExtension = getFilesByExtension as jest.MockedFunction; +const mockedProcessFiles = processFiles as jest.MockedFunction; +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}`); +}); \ No newline at end of file