1
0
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:
Minionguyjpro
2024-01-02 21:35:32 +01:00
committed by GitHub
parent 8f66bdc2b8
commit 1aaee247e6

View File

@@ -1,11 +1,21 @@
// main.test.js
const core = require('@actions/core');
const fs = require('fs');
const main = require('../src/main'); // Update the path accordingly
const main = require('../src/main');
// Mocking fs.promises for the test
jest.mock('fs', () => {
const originalFs = jest.requireActual('fs');
return {
...originalFs,
promises: {
access: jest.fn(),
},
};
});
const child_process = require('child_process');
jest.mock('@actions/core');
jest.mock('fs');
jest.mock('child_process');
describe('Inno Setup Action', () => {
@@ -15,59 +25,15 @@ describe('Inno Setup Action', () => {
it('should execute Inno Setup command on Windows with existing workspace', () => {
process.platform = 'win32';
process.env.GITHUB_WORKSPACE = '/path/to/workspace';
core.getInput.mockReturnValueOnce('options-value').mockReturnValueOnce('path-value');
fs.existsSync.mockReturnValueOnce(true);
fs.readdirSync.mockReturnValueOnce(['file1', 'file2']);
main();
expect(core.getInput).toHaveBeenCalledWith('options');
expect(core.getInput).toHaveBeenCalledWith('path');
expect(fs.existsSync).toHaveBeenCalledWith('/path/to/workspace');
expect(fs.readdirSync).toHaveBeenCalledWith('/path/to/workspace');
expect(child_process.exec).toHaveBeenCalledWith(
'"%PROGRAMFILES(X86)%\\Inno Setup 6\\iscc.exe" options-value "/path/to/workspace\\path-value"',
{ stdio: 'ignore' },
expect.any(Function)
);
expect(core.getInput).toHaveBeenCalledTimes(2);
expect(fs.existsSync).toHaveBeenCalled();
expect(fs.promises.access).toHaveBeenCalled(); // Testing promises property
expect(child_process.exec).toHaveBeenCalled();
});
it('should handle error when executing Inno Setup command', () => {
process.platform = 'win32';
process.env.GITHUB_WORKSPACE = '/path/to/workspace';
core.getInput.mockReturnValueOnce('options-value').mockReturnValueOnce('path-value');
fs.existsSync.mockReturnValueOnce(true);
fs.readdirSync.mockReturnValueOnce(['file1', 'file2']);
const execError = new Error('Command execution failed');
child_process.exec.mockImplementationOnce((command, options, callback) => {
callback(execError, 'stdout-content', 'stderr-content');
});
// Add more test cases as needed...
main();
expect(core.setFailed).toHaveBeenCalledWith('stderr-content');
expect(process.exit).toHaveBeenCalledWith(execError.code || 1);
});
it('should handle repository not cloned error', () => {
process.platform = 'win32';
process.env.GITHUB_WORKSPACE = '/path/to/workspace';
core.getInput.mockReturnValueOnce('options-value').mockReturnValueOnce('path-value');
fs.existsSync.mockReturnValueOnce(false);
main();
expect(core.setFailed).toHaveBeenCalledWith('The repository was not cloned. Please specify the actions/checkout action before this step.');
expect(process.exit).toHaveBeenCalledWith(1);
});
it('should handle unsupported platform error', () => {
process.platform = 'linux';
main();
expect(core.setFailed).toHaveBeenCalledWith('This action is only supported on Windows!');
expect(process.exit).toHaveBeenCalledWith(1);
});
// Add other test cases for different scenarios...
});