Skip to content
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
eb40a1e
Initial plan
Copilot Jul 27, 2025
a6a90be
Replace Jest with Vitest dependencies and configuration
Copilot Jul 27, 2025
2ca1928
Update test files to use Vitest API and create working configuration
Copilot Jul 27, 2025
48c80dd
Complete Jest to Vitest migration with final configuration and docume…
Copilot Jul 27, 2025
fa7e37d
Update lockfile
RichDom2185 Jul 27, 2025
ecde3b4
Reformat files
RichDom2185 Jul 27, 2025
008ba16
Fix test config
RichDom2185 Jul 27, 2025
1ea160f
Remove old jest config
RichDom2185 Jul 27, 2025
be108af
Update dependencies
RichDom2185 Jul 27, 2025
aeb0665
Resolve import inconsistency
RichDom2185 Jul 27, 2025
5477538
Deduplicate dependencies
RichDom2185 Jul 27, 2025
5953417
Rename test files
RichDom2185 Jul 27, 2025
c17daed
Rename snapshots
RichDom2185 Jul 27, 2025
39a0d47
Update some test snapshots
RichDom2185 Jul 27, 2025
22114e2
Update more test snapshots
RichDom2185 Jul 27, 2025
10fe64d
Move past fixes to test setup
RichDom2185 Jul 27, 2025
bb636b1
Remove unnecessary reference types
RichDom2185 Jul 27, 2025
9f109ef
Fix some tests
RichDom2185 Jul 27, 2025
9e07a15
Update remaining snapshots
RichDom2185 Jul 27, 2025
1cf6e5c
Fix more tests
RichDom2185 Jul 27, 2025
dcc4f86
Fix navigation bar tests
RichDom2185 Jul 27, 2025
9210454
Fix some type errors
RichDom2185 Jul 27, 2025
04d6c27
Fix more type errors
RichDom2185 Jul 27, 2025
b9920f5
Update test snapshot
RichDom2185 Jul 27, 2025
83035c6
Update scripts
RichDom2185 Jul 27, 2025
50b75e8
Fix more tests
RichDom2185 Jul 27, 2025
002ed03
Reformat files
RichDom2185 Jul 27, 2025
b4dea5c
Remove double test suffix
RichDom2185 Jul 27, 2025
311bd36
Fix version
RichDom2185 Jul 27, 2025
8a05c15
Prevent opening browser UI on test launch
RichDom2185 Jul 27, 2025
4256067
Fail test early on CI
RichDom2185 Jul 27, 2025
4b817ff
Fix remaining errors
RichDom2185 Jul 27, 2025
bf75c60
Fix more tests and snapshots
RichDom2185 Jul 27, 2025
0a65a36
Fix ESLint issues
RichDom2185 Jul 27, 2025
6a20644
Configure i18next for tests
RichDom2185 Jul 27, 2025
2638e41
Fix coverage generation
RichDom2185 Jul 28, 2025
1be229b
Remove comment
RichDom2185 Jul 28, 2025
34e5020
Resolve imports
RichDom2185 Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
commands: [tsc, 'format:ci', eslint, build, test, test-coveralls]
commands: [tsc, 'format:ci', eslint, build, 'test --bail=1', test-coveralls]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -43,5 +43,5 @@ jobs:
if: matrix.commands == 'test-coveralls'
uses: coverallsapp/github-action@master
with:
path-to-lcov: lcov.info
path-to-lcov: coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ To start contributing, create a fork from our repo and send a PR. Refer to [this

The frontend comes with an extensive test suite. To run the tests after you made your modifications, run
`yarn test`. Regression tests are run automatically when you want to push changes to this repository.
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:
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:

```bash
yarn test --updateSnapshot
yarn test --update
```

## Manually testing the frontend
Expand Down
104 changes: 0 additions & 104 deletions jest.config.js

This file was deleted.

16 changes: 0 additions & 16 deletions jsdom-env.js

This file was deleted.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
"format:scss": "prettier --list-different --parser scss \"src/**/*.scss\"",
"format:ci": "yarn run format:tsx && yarn run format:scss",
"start": "rsbuild dev",
"test": "cross-env TZ=Asia/Singapore jest",
"test": "cross-env TZ=Asia/Singapore vitest run",
"test:watch": "cross-env TZ=Asia/Singapore vitest",
"test:ui": "cross-env TZ=Asia/Singapore vitest --ui --no-open",
"test-coveralls": "./scripts/test-coveralls.sh",
"update-ui-snapshots": "jest --updateSnapshot",
"update-ui-snapshots": "vitest run --update",
"eslint": "eslint src",
"prepare": "husky",
"preview": "rsbuild preview"
Expand Down Expand Up @@ -122,7 +124,6 @@
"@rsbuild/plugin-svgr": "^1.2.0",
"@svgr/webpack": "^8.0.0",
"@swc/core": "^1.11.22",
"@swc/jest": "^0.2.38",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^16.0.0",
Expand All @@ -134,7 +135,6 @@
"@types/gapi.client.drive-v3": "^0.0.5",
"@types/google.picker": "^0.0.51",
"@types/identity-obj-proxy": "^3",
"@types/jest": "^29.0.0",
"@types/js-cookie": "^3.0.6",
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.195",
Expand All @@ -147,7 +147,9 @@
"@types/redux-mock-store": "^1.0.3",
"@types/showdown": "^2.0.1",
"@types/xml2js": "^0.4.11",
"babel-jest": "^29.7.0",
"@vitejs/plugin-react-swc": "^3.11.0",
"@vitest/coverage-v8": "3.2.4",
"@vitest/ui": "^3.2.4",
"buffer": "^6.0.3",
"canvas": "^3.1.0",
"constants-browserify": "^1.0.0",
Expand All @@ -161,8 +163,7 @@
"https-browserify": "^1.0.0",
"husky": "^9.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jsdom": "^25.0.1",
"npm-run-all2": "^8.0.0",
"os-browserify": "^0.3.0",
"path": "^0.12.7",
Expand All @@ -181,6 +182,7 @@
"typescript": "^5.8.2",
"typescript-eslint": "^8.1.0",
"url": "^0.11.1",
"vitest": "^3.2.4",
"webpack-bundle-analyzer": "^4.9.0"
},
"browserslist": {
Expand Down
16 changes: 9 additions & 7 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';
import { defineConfig, loadEnv } from '@rsbuild/core';
import { pluginEslint } from '@rsbuild/plugin-eslint';
import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { pluginSvgr } from '@rsbuild/plugin-svgr';
import { InjectManifest } from '@aaroon/workbox-rspack-plugin';

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

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

if (!/js-slang\/dist\/modules\/loader\/loaders.js/.test(moduleName)) return false
return /Critical dependency: the request of a dependency is an expression/.test(warning.message)
if (!/js-slang\/dist\/modules\/loader\/loaders.js/.test(moduleName)) return false;
return /Critical dependency: the request of a dependency is an expression/.test(
warning.message
);
}

// {
// // Ignore warnings for dependencies that do not ship with a source map.
// // This is because we cannot do anything about our dependencies.
Expand All @@ -124,7 +126,7 @@ export default defineConfig({
new InjectManifest({
swSrc: './src/service-worker.ts',
swDest: 'service-worker.js',
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024,
maximumFileSizeToCacheInBytes: 20 * 1024 * 1024
})
];

Expand Down
4 changes: 2 additions & 2 deletions scripts/test-coveralls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
set -euo pipefail

./scripts/coverage-fix.sh do && \
yarn test --coverage --coverageReporters=text-lcov \
--collectCoverageFrom='!**/src/features/game/**' > lcov.info
yarn test --coverage --coverage.reporter=lcov \
--coverage.exclude='**/src/features/game/**'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`ContentDisplay page renders correctly 1`] = `
<div
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Markdown page renders correctly 1`] = `
<div
Expand Down
19 changes: 19 additions & 0 deletions src/commons/application/__tests__/Application.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useTypedSelector } from 'src/commons/utils/Hooks';
import { shallowRender } from 'src/commons/utils/TestUtils';
import { Mock, vi } from 'vitest';

import Application from '../Application';

vi.mock('react-redux', () => ({
useDispatch: vi.fn(),
useSelector: vi.fn()
}));
const useSelectorMock = useTypedSelector as Mock;

test('Application renders correctly', () => {
useSelectorMock.mockReturnValue({ name: 'Bob' });

const app = <Application />;
const tree = shallowRender(app);
expect(tree).toMatchSnapshot();
});
30 changes: 0 additions & 30 deletions src/commons/application/__tests__/Application.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Application renders correctly 1`] = `
<Context.Provider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`available Python language configurations matches snapshot 1`] = `
exports[`available Python language configurations > matches snapshot 1`] = `
[
{
"chapter": -4,
Expand All @@ -14,7 +14,7 @@ exports[`available Python language configurations matches snapshot 1`] = `
]
`;

exports[`available Scheme language configurations matches snapshot 1`] = `
exports[`available Scheme language configurations > matches snapshot 1`] = `
[
{
"chapter": -9,
Expand Down Expand Up @@ -69,7 +69,7 @@ exports[`available Scheme language configurations matches snapshot 1`] = `
]
`;

exports[`available Source language configurations matches snapshot 1`] = `
exports[`available Source language configurations > matches snapshot 1`] = `
[
{
"chapter": 1,
Expand Down Expand Up @@ -256,4 +256,4 @@ exports[`available Source language configurations matches snapshot 1`] = `
]
`;

exports[`getLanguageConfig throws an error for an invalid chapter/variant combination 1`] = `"Language config not found for chapter 5 variant default"`;
exports[`getLanguageConfig > throws an error for an invalid chapter/variant combination 1`] = `[Error: Language config not found for chapter 5 variant default]`;
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,12 @@ test('updateTeamFormationOverviews generates correct action object', () => {
});
});

test('updateGrading generates correct action object', () => {
test('updateGrading generates correct action object', async () => {
const submissionId = 3;
const grading: GradingQuery = {
answers: [
{
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
question: await vi.importMock('../../../../features/grading/GradingTypes'),
student: {
name: 'test student',
username: 'E0123456',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ test('UPDATE_ASSESSMENT_OVERVIEWS works correctly in updating assessment overvie
const gradingTest1: GradingQuery = {
answers: [
{
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
question: await vi.importMock('../../../../features/grading/GradingTypes'),
student: {
name: 'test student',
username: 'E0123456',
Expand Down Expand Up @@ -432,7 +432,7 @@ const gradingTest1: GradingQuery = {
const gradingTest2: GradingQuery = {
answers: [
{
question: jest.genMockFromModule('../../../../features/grading/GradingTypes'),
question: await vi.importMock('../../../../features/grading/GradingTypes'),
student: {
name: 'another test student',
username: 'E0000000',
Expand Down
Loading
Loading