Skip to content

Commit 910162d

Browse files
CopilotRichDom2185
andauthored
Migrate testing setup from Jest to Vitest (#3261)
* Initial plan * Replace Jest with Vitest dependencies and configuration Co-authored-by: RichDom2185 <[email protected]> * Update test files to use Vitest API and create working configuration Co-authored-by: RichDom2185 <[email protected]> * Complete Jest to Vitest migration with final configuration and documentation updates Co-authored-by: RichDom2185 <[email protected]> * Update lockfile * Reformat files * Fix test config * Remove old jest config * Update dependencies * Resolve import inconsistency * Deduplicate dependencies * Rename test files * Rename snapshots * Update some test snapshots * Update more test snapshots * Move past fixes to test setup * Remove unnecessary reference types * Fix some tests * Update remaining snapshots * Fix more tests * Fix navigation bar tests * Fix some type errors * Fix more type errors * Update test snapshot * Update scripts * Fix more tests * Reformat files * Remove double test suffix * Fix version * Prevent opening browser UI on test launch * Fail test early on CI * Fix remaining errors * Fix more tests and snapshots * Fix ESLint issues * Configure i18next for tests * Fix coverage generation * Remove comment * Resolve imports --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: RichDom2185 <[email protected]>
1 parent 45fdca2 commit 910162d

File tree

120 files changed

+1900
-2706
lines changed

Some content is hidden

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

120 files changed

+1900
-2706
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
commands: [tsc, 'format:ci', eslint, build, test, test-coveralls]
25+
commands: [tsc, 'format:ci', eslint, build, 'test --bail=1', test-coveralls]
2626
steps:
2727
- name: Checkout repository
2828
uses: actions/checkout@v4
@@ -43,5 +43,5 @@ jobs:
4343
if: matrix.commands == 'test-coveralls'
4444
uses: coverallsapp/github-action@master
4545
with:
46-
path-to-lcov: lcov.info
46+
path-to-lcov: coverage/lcov.info
4747
github-token: ${{ secrets.GITHUB_TOKEN }}

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ To start contributing, create a fork from our repo and send a PR. Refer to [this
1616

1717
The frontend comes with an extensive test suite. To run the tests after you made your modifications, run
1818
`yarn test`. Regression tests are run automatically when you want to push changes to this repository.
19-
The regression tests are generated using `jest` and stored as snapshots in `src/\_\_tests\_\_`. After modifying the frontend, carefully inspect any failing regression tests reported in red in the command line. If you are convinced that the regression tests and not your changes are at fault, you can update the regression tests by running:
19+
The regression tests are generated using `vitest` and stored as snapshots in `src/\_\_tests\_\_`. After modifying the frontend, carefully inspect any failing regression tests reported in red in the command line. If you are convinced that the regression tests and not your changes are at fault, you can update the regression tests by running:
2020

2121
```bash
22-
yarn test --updateSnapshot
22+
yarn test --update
2323
```
2424

2525
## Manually testing the frontend

jest.config.js

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

jsdom-env.js

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

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
"format:scss": "prettier --list-different --parser scss \"src/**/*.scss\"",
2222
"format:ci": "yarn run format:tsx && yarn run format:scss",
2323
"start": "rsbuild dev",
24-
"test": "cross-env TZ=Asia/Singapore jest",
24+
"test": "cross-env TZ=Asia/Singapore vitest run",
25+
"test:watch": "cross-env TZ=Asia/Singapore vitest",
26+
"test:ui": "cross-env TZ=Asia/Singapore vitest --ui --no-open",
2527
"test-coveralls": "./scripts/test-coveralls.sh",
26-
"update-ui-snapshots": "jest --updateSnapshot",
28+
"update-ui-snapshots": "vitest run --update",
2729
"eslint": "eslint src",
2830
"prepare": "husky",
2931
"preview": "rsbuild preview"
@@ -122,7 +124,6 @@
122124
"@rsbuild/plugin-svgr": "^1.2.0",
123125
"@svgr/webpack": "^8.0.0",
124126
"@swc/core": "^1.11.22",
125-
"@swc/jest": "^0.2.38",
126127
"@testing-library/dom": "^10.4.0",
127128
"@testing-library/jest-dom": "^6.0.0",
128129
"@testing-library/react": "^16.0.0",
@@ -134,7 +135,6 @@
134135
"@types/gapi.client.drive-v3": "^0.0.5",
135136
"@types/google.picker": "^0.0.51",
136137
"@types/identity-obj-proxy": "^3",
137-
"@types/jest": "^29.0.0",
138138
"@types/js-cookie": "^3.0.6",
139139
"@types/js-yaml": "^4.0.5",
140140
"@types/lodash": "^4.14.195",
@@ -147,7 +147,9 @@
147147
"@types/redux-mock-store": "^1.0.3",
148148
"@types/showdown": "^2.0.1",
149149
"@types/xml2js": "^0.4.11",
150-
"babel-jest": "^29.7.0",
150+
"@vitejs/plugin-react-swc": "^3.11.0",
151+
"@vitest/coverage-v8": "3.2.4",
152+
"@vitest/ui": "^3.2.4",
151153
"buffer": "^6.0.3",
152154
"canvas": "^3.1.0",
153155
"constants-browserify": "^1.0.0",
@@ -161,8 +163,7 @@
161163
"https-browserify": "^1.0.0",
162164
"husky": "^9.0.0",
163165
"identity-obj-proxy": "^3.0.0",
164-
"jest": "^29.7.0",
165-
"jest-environment-jsdom": "^29.7.0",
166+
"jsdom": "^25.0.1",
166167
"npm-run-all2": "^8.0.0",
167168
"os-browserify": "^0.3.0",
168169
"path": "^0.12.7",
@@ -181,6 +182,7 @@
181182
"typescript": "^5.8.2",
182183
"typescript-eslint": "^8.1.0",
183184
"url": "^0.11.1",
185+
"vitest": "^3.2.4",
184186
"webpack-bundle-analyzer": "^4.9.0"
185187
},
186188
"browserslist": {

rsbuild.config.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';
12
import { defineConfig, loadEnv } from '@rsbuild/core';
23
import { pluginEslint } from '@rsbuild/plugin-eslint';
34
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
45
import { pluginReact } from '@rsbuild/plugin-react';
56
import { pluginSass } from '@rsbuild/plugin-sass';
67
import { pluginSvgr } from '@rsbuild/plugin-svgr';
7-
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';
88

99
const { publicVars, rawPublicVars } = loadEnv({ prefixes: ['REACT_APP_'] });
1010

@@ -91,13 +91,15 @@ export default defineConfig({
9191
(warning: any) => {
9292
// Ignore the warnings that occur because js-slang uses dynamic imports
9393
// to load Source modules
94-
const moduleName = warning.moduleDescriptor?.name
95-
if (!moduleName) return false
94+
const moduleName = warning.moduleDescriptor?.name;
95+
if (!moduleName) return false;
9696

97-
if (!/js-slang\/dist\/modules\/loader\/loaders.js/.test(moduleName)) return false
98-
return /Critical dependency: the request of a dependency is an expression/.test(warning.message)
97+
if (!/js-slang\/dist\/modules\/loader\/loaders.js/.test(moduleName)) return false;
98+
return /Critical dependency: the request of a dependency is an expression/.test(
99+
warning.message
100+
);
99101
}
100-
102+
101103
// {
102104
// // Ignore warnings for dependencies that do not ship with a source map.
103105
// // This is because we cannot do anything about our dependencies.
@@ -124,7 +126,7 @@ export default defineConfig({
124126
new InjectManifest({
125127
swSrc: './src/service-worker.ts',
126128
swDest: 'service-worker.js',
127-
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024,
129+
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024
128130
})
129131
];
130132

scripts/test-coveralls.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
set -euo pipefail
44

55
./scripts/coverage-fix.sh do && \
6-
yarn test --coverage --coverageReporters=text-lcov \
7-
--collectCoverageFrom='!**/src/features/game/**' > lcov.info
6+
yarn test --coverage --coverage.reporter=lcov \
7+
--coverage.exclude='**/src/features/game/**'
File renamed without changes.

src/commons/__tests__/__snapshots__/ContentDisplay.tsx.snap renamed to src/commons/__tests__/__snapshots__/ContentDisplay.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`ContentDisplay page renders correctly 1`] = `
44
<div

0 commit comments

Comments
 (0)