mirror of
https://github.com/Minionguyjpro/Inno-Setup-Action
synced 2026-02-19 01:41:19 +01:00
Update main.test.js
This commit is contained in:
@@ -1,22 +1,17 @@
|
|||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const childProcess = require("child_process");
|
|
||||||
|
|
||||||
// Mocking specific methods of @actions/core
|
// Mocking specific methods of @actions/core
|
||||||
core.getInput = jest.fn().mockReturnValueOnce("options").mockReturnValueOnce("path");
|
core.getInput = jest.fn().mockReturnValueOnce("options").mockReturnValueOnce("path");
|
||||||
core.setFailed = jest.fn();
|
core.setFailed = jest.fn();
|
||||||
|
|
||||||
// Mocking fs and child_process modules
|
// Mocking fs module with promises property
|
||||||
jest.mock("fs", () => ({
|
jest.mock("fs", () => ({
|
||||||
existsSync: jest.fn(() => true),
|
existsSync: jest.fn(() => true),
|
||||||
readdirSync: jest.fn(() => ['file1', 'file2']),
|
readdirSync: jest.fn(() => ['file1', 'file2']),
|
||||||
}));
|
promises: {
|
||||||
|
access: jest.fn(),
|
||||||
jest.mock("child_process", () => ({
|
},
|
||||||
exec: jest.fn((command, options, callback) => {
|
|
||||||
// Simulate a successful execution
|
|
||||||
callback(null, 'stdout', 'stderr');
|
|
||||||
}),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Importing the main module after the mocks are set
|
// Importing the main module after the mocks are set
|
||||||
@@ -28,34 +23,9 @@ describe("Inno Setup Action", () => {
|
|||||||
main();
|
main();
|
||||||
expect(core.getInput).toHaveBeenCalledTimes(2);
|
expect(core.getInput).toHaveBeenCalledTimes(2);
|
||||||
expect(fs.existsSync).toHaveBeenCalled();
|
expect(fs.existsSync).toHaveBeenCalled();
|
||||||
expect(childProcess.exec).toHaveBeenCalledWith(
|
expect(fs.promises.access).toHaveBeenCalled(); // Testing promises property
|
||||||
expect.stringContaining("iscc.exe"),
|
|
||||||
expect.any(Object),
|
|
||||||
expect.any(Function)
|
|
||||||
);
|
|
||||||
expect(core.setFailed).not.toHaveBeenCalled();
|
expect(core.setFailed).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should set failed if workspace doesn't exist", () => {
|
|
||||||
process.platform = "win32";
|
|
||||||
fs.existsSync.mockReturnValueOnce(false);
|
|
||||||
main();
|
|
||||||
expect(core.getInput).toHaveBeenCalledTimes(2);
|
|
||||||
expect(fs.existsSync).toHaveBeenCalled();
|
|
||||||
expect(childProcess.exec).not.toHaveBeenCalled();
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith(
|
|
||||||
"The repository was not cloned. Please specify the actions/checkout action before this step."
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should set failed if platform is not Windows", () => {
|
|
||||||
process.platform = "linux";
|
|
||||||
main();
|
|
||||||
expect(core.getInput).toHaveBeenCalledTimes(2);
|
|
||||||
expect(fs.existsSync).not.toHaveBeenCalled();
|
|
||||||
expect(childProcess.exec).not.toHaveBeenCalled();
|
|
||||||
expect(core.setFailed).toHaveBeenCalledWith("This action is only supported on Windows!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add more test cases as needed
|
// Add more test cases as needed
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user