1
0
mirror of https://github.com/Minionguyjpro/Inno-Setup-Action synced 2026-02-18 17:41:18 +01:00

Update again...

This commit is contained in:
Minionguyjpro
2024-01-02 20:26:27 +01:00
parent 4784c278e6
commit ef12f606bc
2 changed files with 71 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:

70
__tests__/main.test.js Normal file
View File

@@ -0,0 +1,70 @@
// main.test.js
const fs = require('fs');
const childProcess = require('child_process');
const { testFunction } = require('../src/main');
jest.mock('@actions/core', () => ({
getInput: jest.fn(),
setFailed: jest.fn(),
}));
jest.mock('fs', () => ({
existsSync: jest.fn(),
readdirSync: jest.fn(),
}));
jest.mock('child_process', () => ({
exec: jest.fn(),
}));
describe('Test suite for index.js', () => {
beforeEach(() => {
// Clear mock calls before each test
jest.clearAllMocks();
});
test('Handles Windows platform with existing repository', () => {
process.platform = 'win32';
fs.existsSync.mockReturnValue(true);
fs.readdirSync.mockReturnValue(['file1', 'file2']);
childProcess.exec.mockImplementation((command, options, callback) => {
// Simulate successful execution
callback(null, 'stdout content', 'stderr content');
});
// Call the function you want to test
testFunction();
// Assertions
expect(fs.existsSync).toHaveBeenCalledWith(process.env.GITHUB_WORKSPACE);
expect(fs.readdirSync).toHaveBeenCalledWith(process.env.GITHUB_WORKSPACE);
expect(childProcess.exec).toHaveBeenCalled();
expect(core.setFailed).not.toHaveBeenCalled();
});
test('Handles Windows platform with missing repository', () => {
process.platform = 'win32';
fs.existsSync.mockReturnValue(false);
// Call the function you want to test
testFunction();
// Assertions
expect(core.setFailed).toHaveBeenCalledWith(
'The repository was not cloned. Please specify the actions/checkout action before this step.'
);
expect(process.exit).toHaveBeenCalledWith(1);
});
test('Handles non-Windows platform', () => {
process.platform = 'linux';
// Call the function you want to test
testFunction();
// Assertions
expect(core.setFailed).toHaveBeenCalledWith('This action is only supported on Windows!');
expect(process.exit).toHaveBeenCalledWith(1);
});
});