Skip to content

Commit 1fd77f1

Browse files
authored
Migrate from Jest to Vitest (#3173)
* first part of transition * second part of transition * remove jest * bump up node version and playwright version * update all screenshots because of the new playwright version * fix tests * one more screenshot update
1 parent 48d0ed2 commit 1fd77f1

File tree

899 files changed

+1686
-2509
lines changed

Some content is hidden

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

899 files changed

+1686
-2509
lines changed

.github/workflows/checks.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Setup node
3535
uses: actions/setup-node@v4
3636
with:
37-
node-version: 22.11.0
37+
node-version: 22.14.0
3838
cache: 'yarn'
3939

4040
- name: Cache node_modules
@@ -70,7 +70,7 @@ jobs:
7070
- name: Setup node
7171
uses: actions/setup-node@v4
7272
with:
73-
node-version: 22.11.0
73+
node-version: 22.14.0
7474
cache: 'yarn'
7575

7676
- name: Cache node_modules
@@ -133,7 +133,7 @@ jobs:
133133
- name: Setup node
134134
uses: actions/setup-node@v4
135135
with:
136-
node-version: 22.11.0
136+
node-version: 22.14.0
137137
cache: 'yarn'
138138

139139
- name: Cache node_modules
@@ -163,8 +163,8 @@ jobs:
163163
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
164164
exit "$exitcode"
165165
166-
jest_tests:
167-
name: Jest tests
166+
vitest_tests:
167+
name: Unit tests
168168
needs: [ code_quality, envs_validation ]
169169
runs-on: ubuntu-latest
170170
steps:
@@ -176,7 +176,7 @@ jobs:
176176
- name: Setup node
177177
uses: actions/setup-node@v4
178178
with:
179-
node-version: 22.11.0
179+
node-version: 22.14.0
180180
cache: 'yarn'
181181

182182
- name: Cache node_modules
@@ -195,8 +195,8 @@ jobs:
195195
if: steps.cache-node-modules.outputs.cache-hit == 'true'
196196
run: yarn chakra:typegen
197197

198-
- name: Run Jest
199-
run: yarn test:jest ${{ github.event_name == 'pull_request' && '--changedSince=origin/main' || '' }} --passWithNoTests
198+
- name: Run Vitest
199+
run: yarn test:vitest ${{ github.event_name == 'pull_request' && '--changed=origin/main' || '' }} --passWithNoTests
200200

201201
pw_affected_tests:
202202
name: Resolve affected Playwright tests
@@ -212,7 +212,7 @@ jobs:
212212
- name: Setup node
213213
uses: actions/setup-node@v4
214214
with:
215-
node-version: 22.11.0
215+
node-version: 22.14.0
216216
cache: 'yarn'
217217

218218
- name: Cache node_modules
@@ -254,7 +254,7 @@ jobs:
254254
(needs.pw_affected_tests.result == 'success' || needs.pw_affected_tests.result == 'skipped')
255255
runs-on: ubuntu-latest
256256
container:
257-
image: mcr.microsoft.com/playwright:v1.49.0-noble
257+
image: mcr.microsoft.com/playwright:v1.57.0-noble
258258

259259
strategy:
260260
fail-fast: false
@@ -273,7 +273,7 @@ jobs:
273273
- name: Setup node
274274
uses: actions/setup-node@v4
275275
with:
276-
node-version: 22.11.0
276+
node-version: 22.14.0
277277
cache: 'yarn'
278278

279279
- name: Cache node_modules

.github/workflows/deploy-main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- '.husky/**'
1010
- '.vscode/**'
1111
- 'docs/**'
12-
- 'jest/**'
12+
- 'vitest/**'
1313
- 'mocks/**'
1414
- 'playwright/**'
1515
- 'stubs/**'

.github/workflows/toolkit-npm-publisher.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup node
3131
uses: actions/setup-node@v4
3232
with:
33-
node-version: '22.11.0'
33+
node-version: '22.14.0'
3434
registry-url: 'https://registry.npmjs.org'
3535

3636
# Ensure npm 11.5.1 is installed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.11.0
1+
>=22.14.0

.vscode/launch.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,5 @@
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "launch",
10-
"name": "Jest: watch current file",
11-
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
12-
"args": [
13-
"${fileBasename}",
14-
"--runInBand",
15-
"--verbose",
16-
"-i",
17-
"--no-cache",
18-
"--watchAll",
19-
"--testTimeout=1000000000",
20-
],
21-
"console": "integratedTerminal",
22-
"internalConsoleOptions": "neverOpen"
23-
}
24-
]
6+
"configurations": [ ]
257
}

.vscode/tasks.json

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -198,34 +198,13 @@
198198
},
199199
},
200200

201-
// JEST TESTS
201+
// VITEST TESTS
202202
{
203203
"type": "npm",
204-
"script": "test:jest",
204+
"script": "test:vitest",
205205
"problemMatcher": [],
206-
"label": "jest",
207-
"detail": "run jest tests",
208-
"presentation": {
209-
"reveal": "always",
210-
"panel": "shared",
211-
"focus": true,
212-
"close": false,
213-
"revealProblems": "onProblem",
214-
},
215-
"icon": {
216-
"color": "terminal.ansiBlue",
217-
"id": "beaker"
218-
},
219-
"runOptions": {
220-
"instanceLimit": 1
221-
}
222-
},
223-
{
224-
"type": "npm",
225-
"script": "test:jest:watch",
226-
"problemMatcher": [],
227-
"label": "jest: watch all",
228-
"detail": "run jest tests in watch mode",
206+
"label": "vitest",
207+
"detail": "run unit tests",
229208
"presentation": {
230209
"reveal": "always",
231210
"panel": "shared",
@@ -243,10 +222,10 @@
243222
},
244223
{
245224
"type": "shell",
246-
"command": "yarn test:jest ${relativeFileDirname}/${fileBasename} --watch",
225+
"command": "yarn test:vitest ${relativeFileDirname}/${fileBasename}",
247226
"problemMatcher": [],
248-
"label": "jest: watch",
249-
"detail": "run jest tests in watch mode for current file",
227+
"label": "vitest: file",
228+
"detail": "run unit tests for current file",
250229
"presentation": {
251230
"reveal": "always",
252231
"panel": "shared",

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# *****************************
22
# *** STAGE 1: Dependencies ***
33
# *****************************
4-
FROM node:22.11.0-alpine AS deps
4+
FROM node:22.14.0-alpine AS deps
55
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
66
RUN apk add --no-cache libc6-compat python3 make g++
77
RUN ln -sf /usr/bin/python3 /usr/bin/python
@@ -67,7 +67,7 @@ RUN yarn --frozen-lockfile --network-timeout 100000
6767
# *****************************
6868
# ****** STAGE 2: Build *******
6969
# *****************************
70-
FROM node:22.11.0-alpine AS builder
70+
FROM node:22.14.0-alpine AS builder
7171
RUN apk add --no-cache --upgrade libc6-compat bash jq
7272

7373
# pass build args to env variables
@@ -144,7 +144,7 @@ RUN cd ./deploy/tools/llms-txt-generator && yarn build
144144
# ******* STAGE 3: Run ********
145145
# *****************************
146146
# Production image, copy all the files and run next
147-
FROM node:22.11.0-alpine AS runner
147+
FROM node:22.14.0-alpine AS runner
148148
RUN apk add --no-cache --upgrade bash curl jq unzip
149149

150150
### APP
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Set of ENVs for Jest unit tests
1+
# Set of ENVs for Vitest unit tests
22

33
# app configuration
44
NEXT_PUBLIC_APP_PROTOCOL=http
@@ -37,7 +37,7 @@ NEXT_PUBLIC_GIT_TAG=v1.0.11
3737
NEXT_PUBLIC_NETWORK_EXPLORERS=[{'title':'Bitquery','baseUrl':'https://explorer.bitquery.io/','paths':{'tx':'/goerli/tx','address':'/goerli/address','token':'/goerli/token','block':'/goerli/block'}},{'title':'Etherscan','baseUrl':'https://goerli.etherscan.io/','paths':{'tx':'/tx','address':'/address','token':'/token','block':'/block'}}]
3838

3939
# app features
40-
NEXT_PUBLIC_APP_INSTANCE=jest
40+
NEXT_PUBLIC_APP_INSTANCE=vitest
4141
NEXT_PUBLIC_APP_ENV=testing
4242
NEXT_PUBLIC_MARKETPLACE_CONFIG_URL=https://localhost:3000/marketplace-config.json
4343
NEXT_PUBLIC_MARKETPLACE_SUBMIT_FORM=https://localhost:3000/marketplace-submit-form

docs/CONTRIBUTING.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ We are using following technology stack in the project
4747
- [Next.js](https://nextjs.org/) as application framework
4848
- [Chakra](https://chakra-ui.com/) as component library; our theme customization can be found in `/theme` folder
4949
- [TanStack Query](https://tanstack.com/query/v4/docs/react/overview/) for fetching, caching and updating data from the API
50-
- [Jest](https://jestjs.io/) as JavaScript testing framework
50+
- [Vitest](https://vitest.dev/) as JavaScript testing framework
5151
- [Playwright](https://playwright.dev/) as a tool for components visual testing
5252
5353
And of course our premier language is [Typescript](https://www.typescriptlang.org/).
@@ -119,13 +119,13 @@ These are the steps that you have to follow to make everything work:
119119
120120
Every feature or bugfix should be accompanied by tests, either unit tests or component visual tests, or both, except from trivial fixes (for example, typo fix). All commands for running tests you can find [below](./CONTRIBUTING.md#command-list).
121121
122-
### Jest unit tests
122+
### Vitest unit tests
123123
124-
If your changes are only related to the logic of the app and not to its visual presentation, then try to write unit tests using [Jest](https://jestjs.io/) framework and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/). In general these tests are "cheaper" and faster than Playwright ones. Use them for testing your utilities and React hooks, as well as the whole components logic.
124+
If your changes are only related to the logic of the app and not to its visual presentation, then try to write unit tests using [Vitest](https://vitest.dev/) framework and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/). In general these tests are "cheaper" and faster than Playwright ones. Use them for testing your utilities and React hooks, as well as the whole components logic.
125125
126-
Place your test suites in `.test.ts` or `.test.tsx` files. You can find or add some mocks or other helpful utilities for these tests purposes in the `/jest` folder.
126+
Place your test suites in `.spec.ts` or `.spec.tsx` files. You can find or add some mocks or other helpful utilities for these tests purposes in the `/vitest` folder.
127127
128-
*Note*, that we are using custom renderer and wrapper in all tests for React components, so please do not import package `@testing-library/react` directly in your test suites, instead use imports from `jest/lib` utility.
128+
*Note*, that we are using custom renderer and wrapper in all tests for React components, so please do not import package `@testing-library/react` directly in your test suites, instead use imports from `vitest/lib` utility.
129129
130130
### Playwright components tests
131131
@@ -198,8 +198,7 @@ We have 3 pre-configured projects. You can run your test with the desired projec
198198
| `yarn svg:format` | format and optimize SVG icons in the `/icons` folder using SVGO tool |
199199
| `yarn svg:build-sprite` | build SVG icons sprite |
200200
| **Testing** |
201-
| `yarn test:jest` | run all Jest unit tests |
202-
| `yarn test:jest:watch` | run all Jest unit tests in watch mode |
201+
| `yarn test:vitest` | run all Vitest unit tests |
203202
| `yarn test:pw:local` | run Playwright component tests locally |
204203
| `yarn test:pw:docker` | run Playwright component tests in docker container |
205204
| `yarn test:pw:ci` | run Playwright component tests in CI |
@@ -214,6 +213,4 @@ We have 3 pre-configured projects. You can run your test with the desired projec
214213

215214
There are some predefined tasks for all commands described above. You can see the full list by pressing <kbd>cmd + shift + P</kbd> and using command `Task: Run task`
216215

217-
Also there is a Jest test launch configuration for debugging and running current test file in the watch mode.
218-
219216
And you may find the Dev Container setup useful too.

eslint.config.mjs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import reactQueryPlugin from '@tanstack/eslint-plugin-query';
66
import consistentDefaultExportNamePlugin from 'eslint-plugin-consistent-default-export-name';
77
import importPlugin from 'eslint-plugin-import';
88
import importHelpersPlugin from 'eslint-plugin-import-helpers';
9-
import jestPlugin from 'eslint-plugin-jest';
109
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
1110
import noCyrillicStringPlugin from 'eslint-plugin-no-cyrillic-string';
1211
import playwrightPlugin from 'eslint-plugin-playwright';
1312
import reactPlugin from 'eslint-plugin-react';
1413
import reactHooksPlugin from 'eslint-plugin-react-hooks';
1514
import * as regexpPlugin from 'eslint-plugin-regexp';
15+
import vitestPlugin from 'eslint-plugin-vitest';
1616
import globals from 'globals';
1717
import path from 'node:path';
1818
import { fileURLToPath } from 'node:url';
@@ -79,14 +79,12 @@ export default tseslint.config(
7979
{
8080
plugins: {
8181
'@typescript-eslint': tseslint.plugin,
82-
jest: jestPlugin,
8382
},
8483
languageOptions: {
8584
parser: tseslint.parser,
8685
parserOptions: {
8786
projectService: true,
8887
},
89-
globals: jestPlugin.environments.globals.globals,
9088
},
9189
rules: {
9290
'@typescript-eslint/array-type': [ 'error', {
@@ -261,10 +259,21 @@ export default tseslint.config(
261259
},
262260

263261
{
264-
files: [ '**/*.test.{ts,js,jsx,tsx}' ],
265-
plugins: { jest: jestPlugin },
262+
files: [ '**/*.spec.{ts,js,jsx,tsx}' ],
263+
plugins: { vitest: vitestPlugin },
264+
rules: {
265+
...vitestPlugin.configs.recommended.rules,
266+
},
267+
settings: {
268+
vitest: {
269+
typecheck: true,
270+
},
271+
},
266272
languageOptions: {
267-
globals: jestPlugin.environments.globals.globals,
273+
globals: {
274+
...vitestPlugin.environments.env.globals,
275+
fetchMock: true,
276+
},
268277
},
269278
},
270279

@@ -297,7 +306,6 @@ export default tseslint.config(
297306
'/^data/',
298307
'/^deploy/',
299308
'/^icons/',
300-
'/^jest/',
301309
'/^lib/',
302310
'/^mocks/',
303311
'/^pages/',
@@ -306,6 +314,7 @@ export default tseslint.config(
306314
'/^theme/',
307315
'/^toolkit/',
308316
'/^ui/',
317+
'/^vitest/',
309318
],
310319
[ 'parent', 'sibling', 'index' ],
311320
],

0 commit comments

Comments
 (0)