Skip to content

Commit

Permalink
🏗️ feat: 迁移 测试框架到 vitest 以提升测试速度
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 9, 2023
1 parent 1ed8978 commit 0a6ee6f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ node_modules

.vercel
server
coverage
35 changes: 0 additions & 35 deletions jest.config.ts

This file was deleted.

21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "umi-simple-web-template",
"version": "1.2.0",
"private": true,
"repository": "https://github.com/arvinxx/umi-simple-web-template.git",
"scripts": {
"build": "max build",
"build:analyze": "ANALYZE=1 max build",
Expand All @@ -10,9 +11,9 @@
"prepare": "husky install",
"release": "semantic-release",
"start": "vercel dev",
"test": "jest --passWithNoTests",
"test:coverage": "jest --coverage --passWithNoTests",
"test:update": "jest -u"
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:update": "vitest -u"
},
"lint-staged": {
"*.{ts,tsx}": [
Expand All @@ -27,27 +28,23 @@
},
"devDependencies": {
"@emotion/jest": "^11",
"@testing-library/jest-dom": "^5",
"@testing-library/react": "^13",
"@types/jest": "^29",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/testing-library__jest-dom": "^5",
"@umijs/max": "^4",
"@vitest/coverage-c8": "latest",
"commitlint": "^17",
"commitlint-config-gitmoji": "^2",
"cross-env": "^7",
"eslint": "^8",
"husky": "^8",
"jest": "^29",
"jest-environment-jsdom": "^29",
"lint-staged": "^13",
"prettier": "^2",
"semantic-release": "^20",
"semantic-release-config-gitmoji": "^1",
"ts-node": "^10",
"typescript": "^4",
"vercel": "^28"
},
"repository": "https://github.com/arvinxx/umi-simple-web-template.git"
"typescript": "^5",
"vercel": "^28",
"vitest": "latest"
}
}
12 changes: 9 additions & 3 deletions src/pages/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`App 默认 1`] = `
exports[`App > 默认 1`] = `
.emotion-0 {
font-family: Georgia,sans-serif;
margin-top: 4em;
text-align: center;
}
@media (max-width: 575px) {
.emotion-0 {
margin-top: 10px;
}
}
.emotion-1 {
height: 512px;
background: url() no-repeat center 0;
background: url(/src/assets/yay.jpg) no-repeat center 0;
-webkit-background-size: 512px 512px;
background-size: 512px 512px;
}
Expand Down
1 change: 0 additions & 1 deletion tests/__mocks__/fileMock.js

This file was deleted.

2 changes: 0 additions & 2 deletions tests/jest-setup.ts

This file was deleted.

2 changes: 2 additions & 0 deletions tests/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { createSerializer } from '@emotion/jest';
expect.addSnapshotSerializer(createSerializer());
15 changes: 15 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
esbuild: {
jsxInject: "import React from 'react'",
},
test: {
setupFiles: './tests/test-setup.ts',
environment: 'jsdom',
globals: true,
alias: {
'@': './src',
},
},
});

1 comment on commit 0a6ee6f

@vercel
Copy link

@vercel vercel bot commented on 0a6ee6f Apr 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.