Skip to content

Commit 547efcc

Browse files
authored
chore(deps): upgrade jest (#5517)
1 parent 6d08a5a commit 547efcc

File tree

6 files changed

+1323
-980
lines changed

6 files changed

+1323
-980
lines changed

web/jest.config.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
module.exports = {
2+
// Use jsdom environment for DOM testing
3+
testEnvironment: 'jsdom',
4+
5+
// Setup files to run before tests
6+
setupFilesAfterEnv: ['<rootDir>/src/jest-setup.ts'],
7+
8+
// Transform files with babel (Jest 30 automatically uses babel-jest)
9+
transform: {
10+
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
11+
},
12+
13+
// Module name mapping for imports
14+
moduleNameMapper: {
15+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js',
16+
'\\.(scss|css|less)$': '<rootDir>/__mocks__/styleMock.js',
17+
'@components/(.*)$': '<rootDir>/src/components/$1',
18+
'@features/(.*)$': '<rootDir>/src/features/$1',
19+
'@stores/(.*)$': '<rootDir>/src/stores/$1',
20+
'@types': '<rootDir>/src/types/index',
21+
'@utils': '<rootDir>/src/utilities/index',
22+
'handlebars': '<rootDir>/handlebars/dist/handlebars.js',
23+
'@src/(.*)$': '<rootDir>/src/$1'
24+
},
25+
26+
// Test environment options
27+
testEnvironmentOptions: {
28+
customExportConditions: [''],
29+
},
30+
31+
// Jest worker configuration to prevent process exceptions
32+
maxWorkers: 1,
33+
workerIdleMemoryLimit: '512MB',
34+
35+
// Timeout configuration
36+
testTimeout: 10000,
37+
38+
// Coverage configuration
39+
collectCoverageFrom: [
40+
'src/**/*.{js,jsx,ts,tsx}',
41+
'!src/**/*.d.ts',
42+
'!src/**/*.stories.{js,jsx,ts,tsx}',
43+
'!src/**/*.test.{js,jsx,ts,tsx}',
44+
'!src/**/index.{js,jsx,ts,tsx}',
45+
],
46+
47+
// Test file patterns
48+
testMatch: [
49+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
50+
'<rootDir>/src/**/*.{test,spec}.{js,jsx,ts,tsx}',
51+
],
52+
53+
// Module file extensions
54+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
55+
56+
// Clear mocks between tests
57+
clearMocks: true,
58+
59+
// Restore mocks between tests
60+
restoreMocks: true,
61+
62+
// Reset modules between tests
63+
resetModules: true,
64+
65+
// Collect coverage
66+
collectCoverage: false,
67+
68+
// Coverage directory
69+
coverageDirectory: 'coverage',
70+
71+
// Coverage reporters
72+
coverageReporters: ['text', 'lcov', 'html'],
73+
74+
// Coverage thresholds
75+
coverageThreshold: {
76+
global: {
77+
branches: 80,
78+
functions: 80,
79+
lines: 80,
80+
statements: 80,
81+
},
82+
},
83+
84+
// Verbose output
85+
verbose: true,
86+
87+
// Force exit after tests
88+
forceExit: true,
89+
90+
// Detect open handles
91+
detectOpenHandles: true,
92+
};

web/package.json

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"@pact-foundation/pact": "^15.0.1",
3333
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.1",
3434
"@tanstack/react-query-devtools": "^4.36.1",
35-
"@testing-library/jest-dom": "^6.6.4",
35+
"@testing-library/jest-dom": "^6.8.0",
3636
"@testing-library/react": "^15.0.7",
3737
"@types/downloadjs": "^1.4",
38-
"@types/jest": "^29.5.14",
38+
"@types/jest": "^30.0.0",
3939
"@types/js-yaml": "^3",
4040
"@types/lodash": "^4.17.20",
4141
"@types/node": "^22.15.30",
@@ -57,12 +57,12 @@
5757
"css-loader": "^7.1.2",
5858
"eslint": "^9.32.0",
5959
"eslint-plugin-import": "^2.32.0",
60-
"eslint-plugin-jest": "^28.13.0",
60+
"eslint-plugin-jest": "^29.0.1",
6161
"eslint-webpack-plugin": "^4.2.0",
6262
"html-webpack-plugin": "^5.6.4",
6363
"intersection-observer": "^0.12.2",
64-
"jest": "^29.7.0",
65-
"jest-environment-jsdom": "^29.7.0",
64+
"jest": "^30.1.1",
65+
"jest-environment-jsdom": "^30.1.1",
6666
"jest-fixed-jsdom": "^0.0.10",
6767
"mini-css-extract-plugin": "^2.9.4",
6868
"msw": "^2.10.5",
@@ -145,26 +145,5 @@
145145
"last 4 versions",
146146
"not IE 11",
147147
"not dead"
148-
],
149-
"jest": {
150-
"setupFilesAfterEnv": [
151-
"<rootDir>/src/jest-setup.ts"
152-
],
153-
"testEnvironmentOptions": {
154-
"customExportConditions": [
155-
""
156-
]
157-
},
158-
"moduleNameMapper": {
159-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
160-
"\\.(scss|css|less)$": "<rootDir>/__mocks__/styleMock.js",
161-
"@components/(.*)$": "<rootDir>/src/components/$1",
162-
"@features/(.*)$": "<rootDir>/src/features/$1",
163-
"@stores/(.*)$": "<rootDir>/src/stores/$1",
164-
"@types": "<rootDir>/src/types/index",
165-
"@utils": "<rootDir>/src/utilities/index",
166-
"handlebars": "<rootDir>/handlebars/dist/handlebars.js",
167-
"@src/(.*)$": "<rootDir>/src/$1"
168-
}
169-
}
148+
]
170149
}

web/src/components/upgrade_service/UpgradeService.test.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ describe("UpgradeService", () => {
5555
isConfigurable: true,
5656
hasPreflight: false,
5757
});
58+
}),
59+
http.get(`${api}/apps`, () => {
60+
return HttpResponse.json({
61+
apps: [],
62+
});
63+
}),
64+
http.get(`${api}/upgrade-service/app/${slug}/config`, () => {
65+
return HttpResponse.json({
66+
config: {},
67+
});
5868
})
5969
);
6070

@@ -77,6 +87,23 @@ describe("UpgradeService", () => {
7787
isConfigurable: false,
7888
hasPreflight: true,
7989
});
90+
}),
91+
http.get(`${api}/apps`, () => {
92+
return HttpResponse.json({
93+
apps: [],
94+
});
95+
}),
96+
http.get(`${api}/upgrade-service/app/${slug}/preflight/result`, () => {
97+
return HttpResponse.json({
98+
preflightResult: {
99+
result: {
100+
results: [],
101+
errors: []
102+
},
103+
skipped: false
104+
},
105+
preflightProgress: {}
106+
});
80107
})
81108
);
82109

@@ -101,6 +128,23 @@ describe("UpgradeService", () => {
101128
isConfigurable: false,
102129
hasPreflight: false,
103130
});
131+
}),
132+
http.get(`${api}/apps`, () => {
133+
return HttpResponse.json({
134+
apps: [],
135+
});
136+
}),
137+
http.get(`${api}/upgrade-service/app/${slug}/preflight/result`, () => {
138+
return HttpResponse.json({
139+
preflightResult: {
140+
result: {
141+
results: [],
142+
errors: []
143+
},
144+
skipped: false
145+
},
146+
preflightProgress: {}
147+
});
104148
})
105149
);
106150

@@ -122,6 +166,11 @@ describe("UpgradeService", () => {
122166
server.use(
123167
http.get(`${api}/upgrade-service/app/${slug}`, () => {
124168
return new HttpResponse("Not found", { status: 404 });
169+
}),
170+
http.get(`${api}/apps`, () => {
171+
return HttpResponse.json({
172+
apps: [],
173+
});
125174
})
126175
);
127176

web/src/features/App/api/getApps.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("getApps", () => {
9696
apiEndpoint: testAPIEndpoint,
9797
};
9898

99-
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrowError(
99+
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrow(
100100
"Failed to fetch apps with status 400"
101101
);
102102
});
@@ -115,7 +115,7 @@ describe("getApps", () => {
115115
apiEndpoint: testAPIEndpoint,
116116
};
117117

118-
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrowError(
118+
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrow(
119119
"Error parsing json"
120120
);
121121
});
@@ -130,7 +130,7 @@ describe("getApps", () => {
130130
apiEndpoint: testAPIEndpoint,
131131
};
132132

133-
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrowError(
133+
await expect(getApps(testgetAppsFetchConfig)).rejects.toThrow(
134134
"Error fetching"
135135
);
136136
});

web/src/jest-setup.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,81 @@ import "@testing-library/jest-dom";
44
// Set default API endpoint for tests to prevent undefined URLs
55
process.env.API_ENDPOINT = process.env.API_ENDPOINT || "http://test-api";
66

7+
// Mock fetch globally to prevent actual network calls in tests
8+
const mockFetch = jest.fn().mockImplementation(() =>
9+
Promise.resolve({
10+
ok: true,
11+
status: 200,
12+
json: () => Promise.resolve({ apps: [] }),
13+
text: () => Promise.resolve(""),
14+
headers: new Map(),
15+
clone: function() { return this; }, // Add clone method for MSW compatibility
16+
})
17+
);
18+
global.fetch = mockFetch;
19+
20+
// Mock IntersectionObserver
21+
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
22+
observe: jest.fn(),
23+
unobserve: jest.fn(),
24+
disconnect: jest.fn(),
25+
}));
26+
27+
// Mock ResizeObserver
28+
global.ResizeObserver = jest.fn().mockImplementation(() => ({
29+
observe: jest.fn(),
30+
unobserve: jest.fn(),
31+
disconnect: jest.fn(),
32+
}));
33+
34+
// Mock matchMedia
35+
Object.defineProperty(window, 'matchMedia', {
36+
writable: true,
37+
value: jest.fn().mockImplementation(query => ({
38+
matches: false,
39+
media: query,
40+
onchange: null,
41+
addListener: jest.fn(), // deprecated
42+
removeListener: jest.fn(), // deprecated
43+
addEventListener: jest.fn(),
44+
removeEventListener: jest.fn(),
45+
dispatchEvent: jest.fn(),
46+
})),
47+
});
48+
49+
// Mock window.scrollTo
50+
Object.defineProperty(window, 'scrollTo', {
51+
writable: true,
52+
value: jest.fn(),
53+
});
54+
55+
// Mock window.URL.createObjectURL
56+
Object.defineProperty(window.URL, 'createObjectURL', {
57+
writable: true,
58+
value: jest.fn(() => 'mocked-url'),
59+
});
60+
61+
// Mock window.URL.revokeObjectURL
62+
Object.defineProperty(window.URL, 'revokeObjectURL', {
63+
writable: true,
64+
value: jest.fn(),
65+
});
66+
767
// Global cleanup for Jest
868
afterEach(() => {
969
// Clear any timers and intervals
1070
jest.clearAllTimers();
1171
jest.clearAllMocks();
72+
73+
// Reset fetch mock
74+
mockFetch.mockClear();
1275
});
1376

1477
// Cleanup timers after all tests to prevent worker hanging
1578
afterAll(() => {
1679
// Clear any remaining timers
1780
jest.clearAllTimers();
81+
82+
// Reset fetch mock
83+
mockFetch.mockReset();
1884
});

0 commit comments

Comments
 (0)