Skip to content

Commit cf90956

Browse files
authored
fix: jest test (#107)
* 🐛 improve fs mock in readConfig tests to preserve original functionality * feat: add Babel configuration and update Jest transformation for TypeScript and JavaScript * fix: update ESLint configuration to include babel.config.js in ignored files * chore: build, dist updated
1 parent c558bf8 commit cf90956

File tree

14 files changed

+166710
-76711
lines changed

14 files changed

+166710
-76711
lines changed

__tests__/execute.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { describe, expect, it } from '@jest/globals';
22
import { execute } from '../src/execute';
33

4+
const originalConsoleLog = console.log;
5+
beforeAll(() => {
6+
console.log = jest.fn();
7+
});
8+
afterAll(() => {
9+
console.log = originalConsoleLog;
10+
});
11+
412
describe('execute', () => {
513
it('should execute a command successfully', async () => {
614
// Arrange

__tests__/readConfig.test.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as fs from 'fs';
22
import { readConfig, readJSONSync } from '../src/readConfig';
33

4-
jest.mock('fs', () => ({
5-
existsSync: jest.fn(),
6-
readFileSync: jest.fn(),
7-
promises: {
8-
access: jest.fn()
9-
}
10-
}));
4+
jest.mock('fs', () => {
5+
const actualFs = jest.requireActual('fs');
6+
return {
7+
...actualFs,
8+
existsSync: jest.fn(),
9+
readFileSync: jest.fn(),
10+
promises: {
11+
...actualFs.promises,
12+
access: jest.fn()
13+
}
14+
};
15+
});
1116
jest.mock('@actions/core');
1217

1318
describe('readJSONSync', () => {

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript']
3+
};

0 commit comments

Comments
 (0)