Skip to content

Commit

Permalink
tests: add main test
Browse files Browse the repository at this point in the history
  • Loading branch information
brenoepics committed May 10, 2024
1 parent c1afec2 commit fb5a7b2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions __tests__/main.test.ts
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}`);
});

0 comments on commit fb5a7b2

Please sign in to comment.