Skip to content

Commit 57409cc

Browse files
committed
ODC-6675: Jest runs now
- Switched from `ts-jest` to `esbuild-jest-transform` because `ts-jest` is slow - Updated `i18next-parser` and `esbuild-loader` to latest to avoid duplicate esbuild installations in yarn.lock - Removed `jest-resolver.js` because it was causing issues with resolving files - Jest config moved to `jest.config.ts` because a) it is recommended and b) so we can load `tsconfig` into the esbuild jest transformer
1 parent 1e0e162 commit 57409cc

File tree

6 files changed

+409
-171
lines changed

6 files changed

+409
-171
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* eslint-disable tsdoc/syntax */ // This file is written in JavaScript, so we use JSDoc here. TSDoc rules don't apply
2+
3+
/**
4+
* See https://jestjs.io/docs/configuration#resolver-string
5+
*
6+
* TODO: determine whether this is still needed
7+
*
8+
* @param {string} request
9+
* @param {import('jest-resolve').ResolverOptions} options
10+
*/
11+
// eslint-disable-next-line no-undef
12+
module.exports = (request, options) => {
13+
let packageFilter;
14+
if (request.startsWith('i18next')) {
15+
packageFilter = (pkg) => ({
16+
...pkg,
17+
// Alter the value of `main` before resolving the package
18+
main: pkg.module || pkg.main,
19+
});
20+
}
21+
return options.defaultResolver(request, {
22+
...options,
23+
packageFilter,
24+
});
25+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* A fix for this error:
3+
*
4+
* ● Invalid return value:
5+
* `process()` or/and `processAsync()` method of code transformer found at
6+
* "console/frontend/node_modules/jest-transform-graphql/index.js"
7+
* should return an object or a Promise resolving to an object. The object
8+
* must have `code` property with a string of processed code.
9+
* This error may be caused by a breaking change in Jest 28:
10+
* https://jestjs.io/docs/28.x/upgrading-to-jest28#transformer
11+
* Code Transformation Documentation:
12+
* https://jestjs.io/docs/code-transformation
13+
*
14+
* See https://github.com/remind101/jest-transform-graphql/issues/13
15+
*/
16+
17+
const { process: upstreamProcess } = require('jest-transform-graphql');
18+
19+
const process = (...args) => {
20+
const code = upstreamProcess(...args);
21+
return { code };
22+
};
23+
24+
module.exports = { process };

frontend/jest-resolver.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

frontend/jest.config.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Config } from 'jest';
2+
import { readFileSync } from 'fs';
3+
4+
const tsconfigRaw = readFileSync('./tsconfig.json', 'utf-8');
5+
6+
const config: Config = {
7+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'gql', 'graphql'],
8+
moduleNameMapper: {
9+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
10+
'<rootDir>/__mocks__/fileMock.js',
11+
'\\.(css|less|scss)$': '<rootDir>/__mocks__/styleMock.js',
12+
'^dnd-core$': 'dnd-core/dist/cjs',
13+
'^react-dnd$': 'react-dnd/dist/cjs',
14+
'^react-dnd-html5-backend$': 'react-dnd-html5-backend/dist/cjs',
15+
// the developer insists on publishing with their "editions" package, which is poorly supported
16+
'^binaryextensions$': '<rootDir>/node_modules/binaryextensions/edition-es5',
17+
'^istextorbinary$': '<rootDir>/node_modules/istextorbinary/edition-es5',
18+
'^textextensions$': '<rootDir>/node_modules/textextensions/edition-es5',
19+
},
20+
testEnvironment: 'jsdom',
21+
testRunner: 'jest-jasmine2',
22+
transform: {
23+
'^.+\\.(ts|tsx|js|jsx)$': ['esbuild-jest-transform', { tsconfigRaw }],
24+
'^.+\\.(gql|graphql)$': './__tests__/utils/transform-graphql-jest-28-shim.js',
25+
},
26+
transformIgnorePatterns: [
27+
'<rootDir>/node_modules/(?!(@patternfly(-\\S+)?|d3(-\\S+)?|delaunator|robust-predicates|internmap|lodash-es|istextorbinary|@console|@novnc|@spice-project|@popperjs|i18next(-\\S+)?|@babel/runtime)/.*)',
28+
],
29+
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.*/integration-tests-cypress'],
30+
testRegex: '.*\\.spec\\.(ts|tsx|js|jsx)$',
31+
testEnvironmentOptions: {
32+
url: 'http://localhost',
33+
},
34+
setupFiles: [
35+
'./__mocks__/helmet.ts',
36+
'./__mocks__/localStorage.ts',
37+
'./__mocks__/matchMedia.js',
38+
'./__mocks__/mutationObserver.js',
39+
'./__mocks__/serverFlags.js',
40+
'./__mocks__/websocket.js',
41+
'./before-tests.js',
42+
],
43+
coverageDirectory: '__coverage__',
44+
coverageReporters: ['json', 'lcov', 'text', 'text-summary'],
45+
collectCoverageFrom: [
46+
'public/*.{js,jsx,ts,tsx}',
47+
'public/{components,module,ui}/**/*.{js,jsx,ts,tsx}',
48+
'packages/*/src/**/*.{js,jsx,ts,tsx}',
49+
'!**/node_modules/**',
50+
],
51+
resolver: '<rootDir>/__tests__/utils/jest-resolver.js',
52+
};
53+
54+
export default config;

frontend/package.json

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -74,62 +74,6 @@
7474
"memsource-download": "./i18n-scripts/memsource-download.sh",
7575
"prepare-husky": "cd .. && husky install frontend/.husky"
7676
},
77-
"jest": {
78-
"moduleFileExtensions": [
79-
"js",
80-
"jsx",
81-
"ts",
82-
"tsx",
83-
"json",
84-
"gql",
85-
"graphql"
86-
],
87-
"moduleNameMapper": {
88-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
89-
"\\.(css|less|scss)$": "<rootDir>/__mocks__/styleMock.js",
90-
"^dnd-core$": "dnd-core/dist/cjs",
91-
"^react-dnd$": "react-dnd/dist/cjs",
92-
"^react-dnd-html5-backend$": "react-dnd-html5-backend/dist/cjs"
93-
},
94-
"transform": {
95-
"^.+\\.(ts|tsx|js|jsx)$": "ts-jest",
96-
"^.+\\.(gql|graphql)$": "jest-transform-graphql"
97-
},
98-
"transformIgnorePatterns": [
99-
"<rootDir>/node_modules/(?!(@patternfly(-\\S+)?|d3(-\\S+)?|delaunator|robust-predicates|internmap|lodash-es|@console|@novnc|@spice-project|@popperjs|i18next(-\\S+)?|@babel/runtime)/.*)"
100-
],
101-
"testPathIgnorePatterns": [
102-
"<rootDir>/node_modules/",
103-
"<rootDir>/.*/integration-tests-cypress"
104-
],
105-
"testRegex": ".*\\.spec\\.(ts|tsx|js|jsx)$",
106-
"testEnvironmentOptions": {
107-
"url": "http://localhost"
108-
},
109-
"setupFiles": [
110-
"./__mocks__/helmet.ts",
111-
"./__mocks__/localStorage.ts",
112-
"./__mocks__/matchMedia.js",
113-
"./__mocks__/mutationObserver.js",
114-
"./__mocks__/serverFlags.js",
115-
"./__mocks__/websocket.js",
116-
"./before-tests.js"
117-
],
118-
"coverageDirectory": "__coverage__",
119-
"coverageReporters": [
120-
"json",
121-
"lcov",
122-
"text",
123-
"text-summary"
124-
],
125-
"collectCoverageFrom": [
126-
"public/*.{js,jsx,ts,tsx}",
127-
"public/{components,module,ui}/**/*.{js,jsx,ts,tsx}",
128-
"packages/*/src/**/*.{js,jsx,ts,tsx}",
129-
"!**/node_modules/**"
130-
],
131-
"resolver": "./jest-resolver.js"
132-
},
13377
"dependencies": {
13478
"@patternfly-5/patternfly": "npm:@patternfly/[email protected]",
13579
"@patternfly/patternfly": "^6.2.3",
@@ -235,7 +179,6 @@
235179
"@types/git-url-parse": "^9.0.0",
236180
"@types/glob": "7.x",
237181
"@types/immutable": "3.x",
238-
"@types/jasmine": "2.8.x",
239182
"@types/jest": "^22.x",
240183
"@types/json-schema": "^7.0.7",
241184
"@types/lodash-es": "4.17.x",
@@ -266,6 +209,7 @@
266209
"cypress-jest-adapter": "^0.1.1",
267210
"cypress-multi-reporters": "^1.4.0",
268211
"enzyme": "3.10.x",
212+
"esbuild-jest-transform": "^2.0.1",
269213
"esbuild-loader": "^4.3.0",
270214
"file-loader": "6.2.0",
271215
"find-up": "4.x",
@@ -277,9 +221,10 @@
277221
"husky": "^8.0.3",
278222
"i18next-parser": "^9.3.0",
279223
"i18next-pseudo": "^2.2.0",
280-
"jasmine-core": "2.x",
281224
"jest": "^29.7.0",
282225
"jest-cli": "^29.7.0",
226+
"jest-environment-jsdom": "^29.7.0",
227+
"jest-jasmine2": "^29.7.0",
283228
"jest-junit": "^16.0.0",
284229
"jest-resolve": "^29.7.0",
285230
"jest-transform-graphql": "^2.1.0",
@@ -303,7 +248,6 @@
303248
"sass-loader": "^10.1.1",
304249
"style-loader": "^2.0.0",
305250
"thread-loader": "^4.0.4",
306-
"ts-jest": "^29.3.1",
307251
"ts-node": "10.9.2",
308252
"typescript": "5.7.2",
309253
"val-loader": "^6.0.0",
@@ -318,11 +262,11 @@
318262
"resolutions": {
319263
"@types/react-router": "^5.1.20",
320264
"@types/react-router-dom": "5.3.x",
265+
"esbuild": "^0.25.1",
266+
"glob-parent": "^5.1.2",
321267
"hosted-git-info": "^3.0.8",
322268
"lodash-es": "^4.17.21",
323269
"minimist": "1.2.5",
324-
"ua-parser-js": "^0.7.24",
325-
"glob-parent": "^5.1.2",
326270
"postcss": "^8.2.13",
327271
"async": "^3.2.5"
328272
},

0 commit comments

Comments
 (0)