mirror of
https://github.com/Minionguyjpro/Inno-Setup-Action
synced 2026-02-18 17:41:18 +01:00
Update main.test.js
This commit is contained in:
@@ -1,38 +1,32 @@
|
|||||||
// main.js
|
const main = require("../src/main");
|
||||||
|
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
|
||||||
function main() {
|
// Mocking specific methods of @actions/core
|
||||||
const workspacePath = process.env.GITHUB_WORKSPACE;
|
core.getInput = jest.fn().mockReturnValueOnce("options").mockReturnValueOnce("path");
|
||||||
|
core.setFailed = jest.fn();
|
||||||
|
|
||||||
const options = core.getInput("options");
|
// Mocking fs module with promises property
|
||||||
const path = core.getInput("path");
|
jest.mock("fs", () => ({
|
||||||
|
existsSync: jest.fn(() => true),
|
||||||
|
readdirSync: jest.fn(() => ['file1', 'file2']),
|
||||||
|
promises: {
|
||||||
|
access: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
let repoError;
|
// Importing the main module after the mocks are set
|
||||||
let platformError;
|
const main = require("../src/main");
|
||||||
|
|
||||||
if (process.platform === "win32") {
|
describe("Inno Setup Action", () => {
|
||||||
if (fs.existsSync(workspacePath) && fs.readdirSync(workspacePath).length > 0) {
|
it("should execute Inno Setup command on Windows with existing workspace", () => {
|
||||||
exec(`"%PROGRAMFILES(X86)%\\Inno Setup 6\\iscc.exe" ${options} "${workspacePath}\\${path}"`, { stdio: "ignore" }, function (execError, stdout, stderr) {
|
process.platform = "win32";
|
||||||
console.log(stdout);
|
main();
|
||||||
|
expect(core.getInput).toHaveBeenCalledTimes(2);
|
||||||
|
expect(fs.existsSync).toHaveBeenCalled();
|
||||||
|
expect(fs.promises.access).toHaveBeenCalled(); // Testing promises property
|
||||||
|
expect(core.setFailed).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
if (execError) {
|
// Add more test cases as needed
|
||||||
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;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user