Skip to content

Commit 52eca18

Browse files
fix: fixes the failing CI/CD test in .github/workflows/if-nodejs-pr-testing.yml across all platforms (#4735)
Co-authored-by: Shriya-Chauhan <auroralflower@gmail.com> Co-authored-by: Ansh Goyal <anshgoyal1704@gmail.com>
1 parent 3a1ca24 commit 52eca18

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

scripts/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,7 @@ async function start() {
7676

7777
export { start };
7878

79-
start();
79+
/* istanbul ignore next */
80+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
81+
start();
82+
}

tests/index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,16 @@ describe('start function', () => {
3636
});
3737

3838
test('should throw an error if no finance data is found', async () => {
39-
const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockReturnValue([]);
39+
const originalReaddirSync = fs.readdirSync;
40+
const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockImplementation((path) => {
41+
if (typeof path === 'string' && path.includes('finance')) {
42+
return [] as any;
43+
}
44+
return originalReaddirSync(path as any);
45+
});
4046

4147
await expect(start()).rejects.toThrow('No finance data found in the finance directory.');
42-
expect(readdirSyncSpy).toHaveBeenCalledTimes(1);
48+
expect(readdirSyncSpy).toHaveBeenCalledWith(expect.stringContaining('finance'));
4349
expect(buildFinanceInfoList).not.toHaveBeenCalled();
4450

4551
readdirSyncSpy.mockRestore();

0 commit comments

Comments
 (0)