Skip to content

Commit b6ffcd9

Browse files
authored
Setup Jest unit testing (#534)
Realized in #533 that there were no unit tests within this project. Added support for Jest unit testing.
1 parent 405f179 commit b6ffcd9

File tree

20 files changed

+9222
-4169
lines changed

20 files changed

+9222
-4169
lines changed

.github/workflows/code-qa.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Checkout repository
4646
uses: actions/checkout@v5
4747
- name: Use Node.js ${{ matrix.node-version }}
48-
uses: actions/setup-node@v4
48+
uses: actions/setup-node@v5
4949
with:
5050
node-version: ${{ matrix.node-version }}
5151
- name: Cache Node.js modules
@@ -63,7 +63,9 @@ jobs:
6363
run: npm run eslint:check
6464
- name: Quality check - type check
6565
run: npm run tsc
66-
- name: Quality check - cypress
67-
run: npm run e2e:headless
66+
- name: Quality check - unit tests
67+
run: npm run test:jest
68+
- name: Quality check - cypress e2e tests
69+
run: npm run test:cypress:e2e
6870
- name: Build check
6971
run: npm run build

.github/workflows/markdown-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@v5
2828
- name: Use Node.js ${{ matrix.node-version }}
29-
uses: actions/setup-node@v4
29+
uses: actions/setup-node@v5
3030
with:
3131
node-version: ${{ matrix.node-version }}
3232
- name: Cache Node.js modules

jest.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
moduleNameMapper: {
4+
'^@/(.*)$': '<rootDir>/src/$1',
5+
'^@components/(.*)$': '<rootDir>/src/components/$1',
6+
'^@configs/(.*)$': '<rootDir>/src/configs/$1',
7+
'^@data/(.*)$': '<rootDir>/src/data/$1',
8+
'^@helpers/(.*)$': '<rootDir>/src/helpers/$1',
9+
'^@images/(.*)$': '<rootDir>/src/images/$1',
10+
'^@layouts/(.*)$': '<rootDir>/src/layouts/$1',
11+
'^@styles/(.*)$': '<rootDir>/src/styles/$1',
12+
'^@util/(.*)$': '<rootDir>/src/util/$1',
13+
'\\.(css|less|scss|sass)$': 'jest-transform-stub',
14+
'\\.(svg|png|jpg|jpeg|gif|webp)$': '<rootDir>/jest/svg-mock.js',
15+
},
16+
testEnvironment: 'jsdom',
17+
verbose: true,
18+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
19+
testPathIgnorePatterns: ['/node_modules/', '/cypress/'],
20+
setupFilesAfterEnv: ['<rootDir>/jest/setup.ts'],
21+
transform: {
22+
'^.+\\.(ts|tsx)$': [
23+
'ts-jest',
24+
{
25+
tsconfig: {
26+
jsx: 'react-jsx',
27+
},
28+
},
29+
],
30+
},
31+
};

jest/setup.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import '@testing-library/jest-dom';
2+
3+
// Polyfills for Node.js environment
4+
if (typeof global.TextEncoder === 'undefined') {
5+
global.TextEncoder = require('util').TextEncoder;
6+
}
7+
if (typeof global.TextDecoder === 'undefined') {
8+
global.TextDecoder = require('util').TextDecoder;
9+
}

jest/svg-mock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const React = require('react');
2+
module.exports = React.forwardRef((props, ref) => React.createElement('svg', { ...props, ref }));

0 commit comments

Comments
 (0)