diff --git a/__tests__/main.test.js b/__tests__/main.test.js index d9cade7..4f4a904 100644 --- a/__tests__/main.test.js +++ b/__tests__/main.test.js @@ -1,31 +1,37 @@ +// main.js const core = require("@actions/core"); const fs = require("fs"); -// Mocking specific methods of @actions/core -core.getInput = jest.fn().mockReturnValueOnce("options").mockReturnValueOnce("path"); -core.setFailed = jest.fn(); +function main() { + const workspacePath = process.env.GITHUB_WORKSPACE; -// Mocking fs module with promises property -jest.mock("fs", () => ({ - existsSync: jest.fn(() => true), - readdirSync: jest.fn(() => ['file1', 'file2']), - promises: { - access: jest.fn(), - }, -})); + const options = core.getInput("options"); + const path = core.getInput("path"); -// Importing the main module after the mocks are set -const main = require("../src/main"); + let repoError; + let platformError; -describe("Inno Setup Action", () => { - it("should execute Inno Setup command on Windows with existing workspace", () => { - process.platform = "win32"; - main(); - expect(core.getInput).toHaveBeenCalledTimes(2); - expect(fs.existsSync).toHaveBeenCalled(); - expect(fs.promises.access).toHaveBeenCalled(); // Testing promises property - expect(core.setFailed).not.toHaveBeenCalled(); - }); + if (process.platform === "win32") { + if (fs.existsSync(workspacePath) && fs.readdirSync(workspacePath).length > 0) { + exec(`"%PROGRAMFILES(X86)%\\Inno Setup 6\\iscc.exe" ${options} "${workspacePath}\\${path}"`, { stdio: "ignore" }, function (execError, stdout, stderr) { + console.log(stdout); - // Add more test cases as needed -}); + if (execError) { + repoError = { code: execError.code || 1 }; + core.setFailed(stderr); + process.exit(repoError.code); + } + }); + } else { + repoError = { code: 1 }; + core.setFailed("The repository was not cloned. Please specify the actions/checkout action before this step."); + process.exit(repoError.code); + } + } else { + platformError = { code: 1 }; + core.setFailed("This action is only supported on Windows!"); + process.exit(platformError.code); + } +} + +module.exports = { main };