Skip to content

Commit 5106be3

Browse files
Merge pull request #1564 from finos/vitest-4-bump-and-test-fixes
chore(deps): bump vitest to v4 and fix tests
2 parents ae25f9f + 0e295a7 commit 5106be3

19 files changed

Lines changed: 746 additions & 1448 deletions

package-lock.json

Lines changed: 464 additions & 1167 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
"@types/validator": "^13.15.10",
183183
"@types/yargs": "^17.0.35",
184184
"@vitejs/plugin-react": "^6.0.2",
185-
"@vitest/coverage-v8": "^3.2.7",
185+
"@vitest/coverage-v8": "^4.1.8",
186186
"c8": "^11.0.0",
187187
"cross-env": "^10.1.0",
188188
"cypress": "^15.18.1",
@@ -206,7 +206,7 @@
206206
"typescript-eslint": "^8.61.1",
207207
"vite": "^8.0.14",
208208
"vite-tsconfig-paths": "^5.1.4",
209-
"vitest": "^3.2.7"
209+
"vitest": "^4.1.8"
210210
},
211211
"overrides": {
212212
"rolldown": "1.0.1",

test/1.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import { describe, it, beforeAll, afterAll, beforeEach, afterEach, expect, vi } from 'vitest';
2828
import request from 'supertest';
2929
import { Service } from '../src/service';
30+
import * as config from '../src/config';
3031
import * as db from '../src/db';
3132
import { Proxy } from '../src/proxy';
3233
import { Express } from 'express';
@@ -45,6 +46,8 @@ describe('init', () => {
4546
// Runs before all tests
4647
beforeAll(async function () {
4748
// Starts the service and returns the express app
49+
// Auto-assign free port (prevents EADDRINUSE errors when running tests in parallel)
50+
vi.spyOn(config, 'getUIPort').mockReturnValue(0);
4851
const proxy = new Proxy();
4952
app = await Service.start(proxy);
5053
});
@@ -69,7 +72,7 @@ describe('init', () => {
6972
// Runs after all tests
7073
afterAll(function () {
7174
// Must close the server to avoid EADDRINUSE errors when running tests in parallel
72-
Service.httpServer.close();
75+
Service.httpServer?.close();
7376
});
7477

7578
// Example test: check server is running

test/ConfigLoader.test.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ describe('ConfigLoader', () => {
555555

556556
it(
557557
'should throw error if repository is a valid URL but not a git repository',
558+
{ timeout: 30000 },
558559
async () => {
559560
const source: ConfigurationSource = {
560561
type: 'git',
@@ -579,11 +580,11 @@ describe('ConfigLoader', () => {
579580
/Failed to clone repository/,
580581
);
581582
},
582-
{ timeout: 30000 },
583583
);
584584

585585
it(
586586
'should throw error if repository is a valid git repo but the branch does not exist',
587+
{ timeout: 30000 },
587588
async () => {
588589
const source: ConfigurationSource = {
589590
type: 'git',
@@ -597,44 +598,35 @@ describe('ConfigLoader', () => {
597598
/Failed to checkout branch/,
598599
);
599600
},
600-
{ timeout: 30000 },
601601
);
602602

603-
it(
604-
'should throw error if config path was not found',
605-
async () => {
606-
const source: ConfigurationSource = {
607-
type: 'git',
608-
repository: 'https://github.com/finos/git-proxy.git',
609-
path: 'path-not-found.json',
610-
branch: 'main',
611-
enabled: true,
612-
};
603+
it('should throw error if config path was not found', { timeout: 30000 }, async () => {
604+
const source: ConfigurationSource = {
605+
type: 'git',
606+
repository: 'https://github.com/finos/git-proxy.git',
607+
path: 'path-not-found.json',
608+
branch: 'main',
609+
enabled: true,
610+
};
613611

614-
await expect(configLoader.loadFromSource(source)).rejects.toThrow(
615-
/Configuration file not found at/,
616-
);
617-
},
618-
{ timeout: 30000 },
619-
);
612+
await expect(configLoader.loadFromSource(source)).rejects.toThrow(
613+
/Configuration file not found at/,
614+
);
615+
});
620616

621-
it(
622-
'should throw error if config file is not valid JSON',
623-
async () => {
624-
const source: ConfigurationSource = {
625-
type: 'git',
626-
repository: 'https://github.com/finos/git-proxy.git',
627-
path: 'test/fixtures/baz.js',
628-
branch: 'main',
629-
enabled: true,
630-
};
617+
it('should throw error if config file is not valid JSON', { timeout: 30000 }, async () => {
618+
const source: ConfigurationSource = {
619+
type: 'git',
620+
repository: 'https://github.com/finos/git-proxy.git',
621+
path: 'test/fixtures/baz.js',
622+
branch: 'main',
623+
enabled: true,
624+
};
631625

632-
await expect(configLoader.loadFromSource(source)).rejects.toThrow(
633-
/Invalid configuration format in git/,
634-
);
635-
},
636-
{ timeout: 30000 },
637-
);
626+
await expect(configLoader.loadFromSource(source)).rejects.toThrow(
627+
/Invalid configuration format in git/,
628+
);
629+
});
638630
});
639631

640632
describe('deepMerge', () => {

test/chain.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ describe('proxy chain', function () {
7777
mockPushProcessors = initMockPushProcessors();
7878
mockPostProcessors = initMockPostProcessors();
7979

80+
// mockPreProcessors lives at module scope so needs manual reset
81+
mockPreProcessors.parseAction.mockReset();
82+
mockPreProcessors.parsePush.mockReset();
83+
8084
// Mock the processors module
8185
vi.doMock('../src/proxy/processors', async () => ({
8286
pre: mockPreProcessors,

test/db/mongo/helper.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ vi.mock('mongodb', async () => {
3737
const actual = await vi.importActual('mongodb');
3838
return {
3939
...actual,
40-
MongoClient: vi.fn(() => mockClient),
40+
MongoClient: vi.fn(function () {
41+
return mockClient;
42+
}),
4143
};
4244
});
4345

0 commit comments

Comments
 (0)