Skip to content

Commit 04ccddb

Browse files
committed
test: Get rid of jest
1 parent d84bdce commit 04ccddb

File tree

9 files changed

+41
-73
lines changed

9 files changed

+41
-73
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dist-ssr
55
*.local
66
.env
77
~*
8+
/coverage/

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ npm run dev
4646

4747
## Todo
4848

49-
- get rid of jest use vitest
5049
- get rid of class-validator (use zod)
5150
- switch to react location
5251
- https://realworld-docs.netlify.app/docs/specs/backend-specs/endpoints

jest.config.js

-35
This file was deleted.

jest.setup.ts

-1
This file was deleted.

package.json

+28-31
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,73 @@
1010
"tscheck": "tsc --noEmit",
1111
"tscheck:w": "npm run tscheck -- --watch --preserveWatchOutput",
1212
"test": "npm run eslint && npm run tscheck && npm run test:cov",
13-
"test:r": "node node_modules/jest/bin/jest --runInBand --verbose",
14-
"test:w": "npm run test:r -- --watch",
15-
"test:cov": "npm run test:r -- --collectCoverage",
13+
"test:r": "vitest run src",
14+
"test:w": "vitest watch src",
15+
"test:cov": "vitest run src --coverage",
1616
"eslint": "node node_modules/eslint/bin/eslint \"src/**/*.{ts,tsx}\"",
1717
"eslint:w": "watchexec -w src \"npm run eslint\"",
1818
"eslint:fix": "npm run eslint -- --fix"
1919
},
2020
"dependencies": {
21-
"@hookform/resolvers": "^2.9.7",
22-
"ahooks": "^3.7.0",
21+
"@hookform/resolvers": "^2.9.8",
22+
"ahooks": "^3.7.1",
2323
"class-transformer": "^0.5.1",
2424
"class-validator": "^0.13.2",
2525
"clsx": "^1.2.1",
2626
"jwt-decode": "^3.1.2",
27-
"ky": "^0.31.1",
27+
"ky": "^0.31.3",
2828
"njct": "^10.0.0",
29-
"react": "^17.0.2",
30-
"react-dom": "^17.0.2",
31-
"react-hook-form": "^7.34.2",
29+
"react": "^18.2.0",
30+
"react-dom": "^18.2.0",
31+
"react-hook-form": "^7.35.0",
3232
"react-router-dom": "^6.3.0",
3333
"recoil": "^0.7.5",
3434
"rsts": "^1.0.0"
3535
},
3636
"devDependencies": {
3737
"@kyleshevlin/eslint-plugin": "^1.3.0",
38-
"@testing-library/jest-dom": "^5.16.5",
39-
"@testing-library/react": "^13.3.0",
40-
"@types/jest": "^28.1.8",
41-
"@types/react": "^17.0.38",
42-
"@types/react-dom": "^17.0.11",
38+
"@testing-library/react": "^13.4.0",
39+
"@types/react": "^18.0.19",
40+
"@types/react-dom": "^18.0.6",
4341
"@types/react-router-dom": "^5.3.3",
44-
"@typescript-eslint/eslint-plugin": "^5.35.1",
45-
"@typescript-eslint/parser": "^5.35.1",
42+
"@typescript-eslint/eslint-plugin": "^5.37.0",
43+
"@typescript-eslint/parser": "^5.37.0",
4644
"@vitejs/plugin-react-refresh": "^1.3.6",
47-
"autoprefixer": "^10.4.8",
45+
"@vitest/coverage-c8": "^0.23.2",
46+
"autoprefixer": "^10.4.10",
4847
"cssnano": "^5.1.13",
4948
"cssnano-preset-default": "^5.2.12",
50-
"eslint": "^8.23.0",
49+
"eslint": "^8.23.1",
5150
"eslint-config-prettier": "^8.5.0",
5251
"eslint-import-resolver-node": "^0.3.6",
53-
"eslint-import-resolver-typescript": "^3.5.0",
54-
"eslint-plugin-boundaries": "^2.10.1",
52+
"eslint-import-resolver-typescript": "^3.5.1",
53+
"eslint-plugin-boundaries": "^3.0.0",
5554
"eslint-plugin-etc": "^2.0.2",
5655
"eslint-plugin-import": "^2.26.0",
5756
"eslint-plugin-only-warn": "^1.0.3",
5857
"eslint-plugin-prettier": "^4.2.1",
5958
"eslint-plugin-promise": "^6.0.1",
60-
"eslint-plugin-react": "^7.31.1",
59+
"eslint-plugin-react": "^7.31.8",
6160
"eslint-plugin-react-hooks": "^4.6.0",
6261
"eslint-plugin-regexp": "^1.9.0",
63-
"eslint-plugin-simple-import-sort": "^7.0.0",
62+
"eslint-plugin-simple-import-sort": "^8.0.0",
6463
"eslint-plugin-sonarjs": "^0.15.0",
65-
"eslint-plugin-sort-class-members": "^1.14.1",
66-
"eslint-plugin-testing-library": "^5.6.0",
64+
"eslint-plugin-sort-class-members": "^1.15.2",
65+
"eslint-plugin-testing-library": "^5.6.4",
6766
"eslint-plugin-unicorn": "^43.0.2",
6867
"eslint-plugin-wix-editor": "^3.3.0",
68+
"happy-dom": "^6.0.4",
6969
"identity-obj-proxy": "^3.0.0",
70-
"jest": "^29.0.1",
71-
"jest-mock-extended": "^2.0.7",
72-
"jest-transform-stub": "^2.0.0",
7370
"npm-run-all": "^4.1.5",
7471
"postcss": "^8.4.16",
7572
"prettier": "^2.7.1",
7673
"simplytyped": "^3.3.0",
7774
"tailwindcss": "^3.1.8",
78-
"ts-jest": "^28.0.8",
79-
"tsconfig-paths-jest-mapper": "^1.4.0",
80-
"typescript": "^4.8.2",
81-
"vite": "^3.0.9",
75+
"typescript": "^4.8.3",
76+
"vite": "^3.1.0",
8277
"vite-tsconfig-paths": "^3.5.0",
78+
"vitest": "^0.23.2",
79+
"vitest-mock-extended": "^0.1.15",
8380
"watchexec-bin": "^1.0.0"
8481
}
8582
}

src/pages/App.spec.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { SessionServiceInterface } from '@application';
22
import { ArticleServiceInterface } from '@application/article';
33
import { render, waitFor } from '@testing-library/react';
4-
import { mock } from 'jest-mock-extended';
54
import { injector } from 'njct';
65
import React from 'react';
76
import { Ok } from 'rsts';
7+
import { afterAll, beforeEach, expect, it, vi } from 'vitest';
8+
import { mock } from 'vitest-mock-extended';
89

910
import { App } from './App';
1011

11-
jest.mock('./home/PopularTags', () => ({ PopularTags: () => 'populartags' }));
12+
vi.mock('./home/PopularTags', () => ({ PopularTags: () => 'populartags' }));
1213

1314
let articleService = mock<ArticleServiceInterface>();
1415
let sessionService = mock<SessionServiceInterface>();

src/pages/article/Article/Article.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function useData(parameters: { slug: string }) {
1111
const [article, setArticle] = useState<SingleArticle | undefined>(undefined);
1212

1313
const getArticle = useCallback(
14-
async slug => {
14+
async (slug: string) => {
1515
const article = await articleService.findOne(slug);
1616
setArticle(article);
1717
},

src/pages/home/PopularTags.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { TagService } from '@application/tag';
12
import { useRequest } from 'ahooks';
23
import { inject } from 'njct';
34
import React from 'react';
4-
import { TagService } from '@application/tag';
55

66
export function PopularTags(): JSX.Element {
77
const { data: tagList, loading } = useRequest(async () => {

vite.config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
/// <reference types="vitest" />
12
import { defineConfig, ConfigEnv, UserConfigExport } from 'vite';
23
import reactRefresh from '@vitejs/plugin-react-refresh';
34
import tsconfigPaths from 'vite-tsconfig-paths';
45

56
// https://vitejs.dev/config/
67
export default function ({}: ConfigEnv): UserConfigExport {
78
return defineConfig({
9+
test: {
10+
threads: false,
11+
reporters: 'dot',
12+
environment: 'happy-dom',
13+
},
814
plugins: [tsconfigPaths(), reactRefresh()],
915
build: {
1016
assetsDir: '.',
11-
brotliSize: false,
17+
// brotliSize: false,
1218
},
1319
});
1420
}

0 commit comments

Comments
 (0)