Skip to content

Commit 3810e14

Browse files
authored
Merge pull request #266 from patternfly/compass_theme_rm_vitest
fix: Remove vitest since it's not compatible with webpack
2 parents adb5011 + bd78c76 commit 3810e14

File tree

7 files changed

+50
-48
lines changed

7 files changed

+50
-48
lines changed

jest.config.cjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
testEnvironment: 'jest-environment-jsdom',
4+
setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'],
5+
moduleNameMapper: {
6+
'\\.(css|less|scss|sass)$': '<rootDir>/src/test/mocks/styleMock.cjs',
7+
'\\.(svg|png|jpg|jpeg|gif|ico|webp)$': '<rootDir>/src/test/mocks/fileMock.cjs',
8+
'^@app/(.*)$': '<rootDir>/src/app/$1',
9+
'monaco-editor': '<rootDir>/src/test/mocks/monaco-editor.ts',
10+
},
11+
transform: {
12+
'^.+\\.(ts|tsx|js|jsx)$': ['ts-jest', { useESM: false }],
13+
},
14+
transformIgnorePatterns: [
15+
'/node_modules/(?!(@patternfly|react-router)/)',
16+
],
17+
testMatch: ['**/__tests__/**/*.(ts|tsx|js)', '**/*.test.(ts|tsx|js)'],
18+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
19+
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts', '!src/test/**'],
20+
};

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"build": "NODE_OPTIONS='--max-old-space-size=4096' webpack --config webpack.prod.js",
1212
"start": "sirv dist --cors --single --host --port 8080",
1313
"start:dev": "webpack serve --color --progress --config webpack.dev.js",
14-
"test": "vitest run",
15-
"test:watch": "vitest",
16-
"test:coverage": "vitest run --coverage",
14+
"test": "jest",
15+
"test:watch": "jest --watch",
16+
"test:coverage": "jest --coverage",
1717
"eslint": "eslint --ext .tsx,.js ./src/",
1818
"lint": "npm run eslint",
1919
"format": "prettier --check --write ./src/**/*.{tsx,ts}",
@@ -25,14 +25,14 @@
2525
},
2626
"devDependencies": {
2727
"@eslint/js": "^9.29.0",
28+
"@testing-library/dom": "^10.4.0",
2829
"@testing-library/jest-dom": "^6.6.3",
2930
"@testing-library/react": "^16.3.0",
3031
"@testing-library/user-event": "^14.6.1",
3132
"@types/react-router-dom": "^5.3.3",
3233
"@typescript-eslint/eslint-plugin": "^8.34.0",
3334
"@typescript-eslint/parser": "^8.34.0",
34-
"@vitejs/plugin-react": "^4.3.3",
35-
"@vitest/coverage-v8": "^4.0.10",
35+
"@types/jest": "^29.5.14",
3636
"copy-webpack-plugin": "^13.0.0",
3737
"css-loader": "^7.1.2",
3838
"css-minimizer-webpack-plugin": "^7.0.2",
@@ -43,7 +43,9 @@
4343
"eslint-plugin-react-hooks": "^5.2.0",
4444
"html-webpack-plugin": "^5.6.3",
4545
"imagemin": "^9.0.0",
46-
"jsdom": "^25.0.1",
46+
"jest": "^29.7.0",
47+
"jest-environment-jsdom": "^29.7.0",
48+
"jest-fixed-jsdom": "^0.0.9",
4749
"mini-css-extract-plugin": "^2.9.2",
4850
"postcss": "^8.4.49",
4951
"prettier": "^3.5.3",
@@ -56,14 +58,13 @@
5658
"style-loader": "^4.0.0",
5759
"svg-url-loader": "^8.0.0",
5860
"terser-webpack-plugin": "^5.3.14",
61+
"ts-jest": "^29.2.5",
5962
"ts-loader": "^9.5.2",
6063
"tsconfig-paths-webpack-plugin": "^4.2.0",
6164
"tslib": "^2.8.1",
6265
"typescript": "^5.8.3",
6366
"typescript-eslint": "^8.34.0",
6467
"url-loader": "^4.1.1",
65-
"vite": "^6.4.1",
66-
"vitest": "^4.0.5",
6768
"webpack": "^5.97.0",
6869
"webpack-bundle-analyzer": "^4.10.2",
6970
"webpack-cli": "^5.1.4",

src/app/app.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as React from 'react';
22
import App from '@app/index';
33
import { render, screen } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
5-
import { describe, expect, it, test } from 'vitest';
65

76
describe('App tests', () => {
87
test('should render default App component', () => {

src/test/mocks/fileMock.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'test-file-stub';

src/test/mocks/styleMock.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};

src/test/setup.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
1+
import { TextDecoder, TextEncoder } from 'util';
12
import '@testing-library/jest-dom';
2-
import { vi } from 'vitest';
3+
4+
// Polyfill for jsdom (react-router etc. may use these)
5+
global.TextEncoder = TextEncoder;
6+
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
37

48
// Mock PatternFly Chatbot MessageBar to avoid monaco-editor dependency
5-
vi.mock('@patternfly/chatbot/dist/dynamic/MessageBar', () => ({
6-
MessageBar: vi.fn(() => null),
9+
jest.mock('@patternfly/chatbot/dist/dynamic/MessageBar', () => ({
10+
MessageBar: jest.fn(() => null),
711
}));
812

913
// Mock CSS imports
1014
Object.defineProperty(window, 'matchMedia', {
1115
writable: true,
12-
value: vi.fn().mockImplementation(query => ({
16+
value: jest.fn().mockImplementation((query: string) => ({
1317
matches: false,
1418
media: query,
1519
onchange: null,
16-
addListener: vi.fn(), // deprecated
17-
removeListener: vi.fn(), // deprecated
18-
addEventListener: vi.fn(),
19-
removeEventListener: vi.fn(),
20-
dispatchEvent: vi.fn(),
20+
addListener: jest.fn(),
21+
removeListener: jest.fn(),
22+
addEventListener: jest.fn(),
23+
removeEventListener: jest.fn(),
24+
dispatchEvent: jest.fn(),
2125
})),
2226
});
2327

2428
// Mock ResizeObserver
2529
global.ResizeObserver = class ResizeObserver {
26-
observe = vi.fn();
27-
unobserve = vi.fn();
28-
disconnect = vi.fn();
30+
observe = jest.fn();
31+
unobserve = jest.fn();
32+
disconnect = jest.fn();
2933
};
3034

3135
// Mock IntersectionObserver
3236
global.IntersectionObserver = class IntersectionObserver {
33-
observe = vi.fn();
34-
unobserve = vi.fn();
35-
disconnect = vi.fn();
37+
observe = jest.fn();
38+
unobserve = jest.fn();
39+
disconnect = jest.fn();
3640
} as any;

vitest.config.ts

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

0 commit comments

Comments
 (0)