Skip to content

Commit bd3e9be

Browse files
committed
chore: split jest config per project
1 parent 28092cc commit bd3e9be

File tree

72 files changed

+3555
-2547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3555
-2547
lines changed

config/globalSetup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export default () => {
1+
module.exports = () => {
22
process.env.TZ = 'UTC';
3+
console.log('Jest Global Setup: Set timezone to UTC');
34
};

config/jest.setup.js

Lines changed: 93 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,98 @@
1-
// eslint-disable-next-line no-unused-vars
2-
import '@testing-library/jest-dom';
3-
4-
Element.prototype.scrollTo = () => {};
5-
6-
Object.defineProperty(window, 'matchMedia', {
7-
writable: true,
8-
value: jest.fn().mockImplementation((query) => ({
9-
matches: false,
10-
media: query,
11-
onchange: null,
12-
addListener: jest.fn(), // deprecated
13-
removeListener: jest.fn(), // deprecated
14-
addEventListener: jest.fn(),
15-
removeEventListener: jest.fn(),
16-
dispatchEvent: jest.fn(),
17-
})),
18-
});
1+
// @ts-nocheck
2+
/* eslint-disable no-unused-vars */
3+
4+
// Force UTC timezone for consistent date/time behavior across all tests
5+
process.env.TZ = 'UTC';
6+
7+
require('@testing-library/jest-dom');
8+
const { expect } = require('@jest/globals');
9+
10+
// Ensure expect is picked up from Jest
11+
global.expect = expect;
12+
13+
// Setup DOM globals only if Element exists (for JSDOM environment)
14+
if (typeof Element !== 'undefined') {
15+
Element.prototype.scrollTo = () => {};
16+
}
17+
18+
// Setup window globals only in browser environment
19+
if (typeof window !== 'undefined') {
20+
Object.defineProperty(window, 'matchMedia', {
21+
writable: true,
22+
value: jest.fn().mockImplementation((query) => ({
23+
matches: false,
24+
media: query,
25+
onchange: null,
26+
addListener: jest.fn(), // deprecated
27+
removeListener: jest.fn(), // deprecated
28+
addEventListener: jest.fn(),
29+
removeEventListener: jest.fn(),
30+
dispatchEvent: jest.fn(),
31+
})),
32+
});
33+
}
34+
1935
global.ResizeObserver = jest.fn().mockImplementation(() => ({
2036
observe: jest.fn(),
2137
unobserve: jest.fn(),
2238
disconnect: jest.fn(),
2339
}));
40+
41+
// Mock DOM APIs that aren't available in jsdom
42+
global.PointerEvent =
43+
global.PointerEvent ||
44+
function (type, init) {
45+
const event = new MouseEvent(type, init);
46+
event.pointerId = init?.pointerId || 1;
47+
event.pointerType = init?.pointerType || 'mouse';
48+
return event;
49+
};
50+
51+
global.ClipboardEvent =
52+
global.ClipboardEvent ||
53+
function (type, init) {
54+
const event = new Event(type, init);
55+
event.clipboardData = init?.clipboardData || null;
56+
return event;
57+
};
58+
59+
// Mock React useLayoutEffect to avoid warnings in JSDOM
60+
jest.mock('react', () => ({
61+
...jest.requireActual('react'),
62+
useLayoutEffect: jest.requireActual('react').useEffect,
63+
}));
64+
65+
// Suppress React warnings during tests to avoid test failures from pre-existing key warnings
66+
const originalError = console.error;
67+
const originalWarn = console.warn;
68+
69+
beforeEach(() => {
70+
console.error = (...args) => {
71+
const message = typeof args[0] === 'string' ? args[0] : '';
72+
if (
73+
message.includes('Warning: Each child in a list should have a unique "key" prop') ||
74+
message.includes('React keys must be passed directly to JSX without using spread')
75+
) {
76+
return;
77+
}
78+
79+
originalError.call(console, ...args);
80+
};
81+
82+
console.warn = (...args) => {
83+
const message = typeof args[0] === 'string' ? args[0] : '';
84+
if (
85+
message.includes('Warning: Each child in a list should have a unique "key" prop') ||
86+
message.includes('React keys must be passed directly to JSX without using spread')
87+
) {
88+
return;
89+
}
90+
91+
originalWarn.call(console, ...args);
92+
};
93+
});
94+
95+
afterEach(() => {
96+
console.error = originalError;
97+
console.warn = originalWarn;
98+
});

jest.config.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
1-
module.exports = {
2-
testEnvironment: 'jest-environment-jsdom',
3-
verbose: true,
4-
testPathIgnorePatterns: [
5-
'/node_modules/',
6-
'packages/suir-component-mapper/',
7-
'/.nx/'
8-
],
9-
setupFilesAfterEnv: [
10-
'<rootDir>/config/jest.setup.js'
11-
],
12-
collectCoverageFrom: [
13-
'<rootDir>/packages/**/src/**/*.js',
14-
'<rootDir>/packages/**/src/**/*.ts',
15-
'!<rootDir>/packages/**/src/**/*.d.ts',
16-
'!<rootDir>/packages/react-renderer-demo/**/*.js',
17-
'!<rootDir>/packages/suir-component-mapper/**/*.js',
18-
'!<rootDir>/packages/**/dist',
19-
'!<rootDir>/templates/**/*.js',
20-
'!<rootDir>/packages/**/src/**/index.js',
21-
'!<rootDir>/shared/**/*.js'
22-
],
23-
moduleNameMapper: {
24-
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/__mocks__/fileMock.js',
25-
'\\.(css|scss)$': 'identity-obj-proxy'
26-
},
27-
modulePathIgnorePatterns: [
28-
'<rootDir>/templates/',
29-
'<rootDir>/.nx/'
30-
],
31-
globalSetup: '<rootDir>/config/globalSetup.js'
32-
};
1+
const { getJestProjectsAsync } = require('@nx/jest');
2+
const path = require('path');
3+
4+
module.exports = async () => ({
5+
projects: [
6+
...(await getJestProjectsAsync()),
7+
],
8+
setupFilesAfterEnv: [path.resolve(__dirname, './config/jest.setup.js')],
9+
globalSetup: '<rootDir>/config/globalSetup.js',
10+
});

jest.preset.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const nxPreset = require('@nx/jest/preset').default;
2+
const path = require('path');
3+
4+
const setupTestsPath = path.resolve(__dirname, './config/jest.setup.js');
5+
6+
module.exports = {
7+
...nxPreset,
8+
testEnvironment: 'jsdom',
9+
verbose: true,
10+
moduleNameMapper: {
11+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': '<rootDir>/../../__mocks__/fileMock.js',
12+
'\\.(css|scss)$': 'identity-obj-proxy',
13+
},
14+
transformIgnorePatterns: ['node_modules/(?!(@testing-library|@data-driven-forms)/)'],
15+
setupFilesAfterEnv: [setupTestsPath, 'jest-canvas-mock'],
16+
testPathIgnorePatterns: ['/node_modules/', 'packages/suir-component-mapper/', 'packages/parsers/', '/templates/', '/.nx/'],
17+
collectCoverageFrom: [
18+
'<rootDir>/../../packages/**/src/**/*.{js,ts,tsx}',
19+
'!<rootDir>/../../packages/**/src/**/*.d.ts',
20+
'!<rootDir>/../../packages/react-renderer-demo/**/*.js',
21+
'!<rootDir>/../../packages/suir-component-mapper/**/*.js',
22+
'!<rootDir>/../../packages/**/dist',
23+
'!<rootDir>/../../templates/**/*.js',
24+
'!<rootDir>/../../packages/**/src/**/index.{js,ts}',
25+
'!<rootDir>/../../shared/**/*.js',
26+
'!<rootDir>/../../packages/**/src/tests/**/*',
27+
],
28+
};

nx.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"plugins": [
99
{
1010
"plugin": "@nx/js",
11-
"exclude": ["**/node_modules/**"],
11+
"exclude": ["**/node_modules/**", "**/templates/**"],
1212
"options": {
1313
"typecheck": {
1414
"targetName": "typecheck"
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"plugin": "@nx/js/typescript",
23-
"exclude": ["**/node_modules/**"],
23+
"exclude": ["**/node_modules/**", "**/templates/**"],
2424
"options": {
2525
"typecheck": {
2626
"targetName": "typecheck"

0 commit comments

Comments
 (0)