Skip to content

Commit

Permalink
feat: add vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
wushengzhu committed May 7, 2024
1 parent ac69238 commit 522d162
Show file tree
Hide file tree
Showing 9 changed files with 1,390 additions and 49 deletions.
5 changes: 3 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

registry=https://registry.npmjs.org/
# registry=https://registry.npmjs.org/
registry=https://registry.npmmirror.com/
auto-install-peers=true
strict-peer-dependencies=false
strict-peer-dependencies=false
21 changes: 11 additions & 10 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/dist/*
.local
.output.js
/node_modules/**

**/*.svg
**/*.sh

/public/*
/lib/*
/dist/*
.local
.output.js
/node_modules/**

**/*.svg
**/*.sh

/public/*
/lib/*
/docs/
64 changes: 32 additions & 32 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
<style>
/* 谷歌与苹果自带浏览器 隐藏浏览器自带滚动条 */
*::-webkit-scrollbar {
display: none;
}

/* 火狐浏览器 隐藏浏览器自带滚动条 */
* {
scrollbar-width: none;
}

/* IE 与微软浏览器 隐藏浏览器自带滚动条 */
* {
-ms-overflow-style: none;
}
</style>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>mutiplexed-elplus</title>
<style>
/* 谷歌与苹果自带浏览器 隐藏浏览器自带滚动条 */
*::-webkit-scrollbar {
display: none;
}

/* 火狐浏览器 隐藏浏览器自带滚动条 */
* {
scrollbar-width: none;
}

/* IE 与微软浏览器 隐藏浏览器自带滚动条 */
* {
-ms-overflow-style: none;
}
</style>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>

</html>
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"prettier": "prettier --write src/**/*.{js,jsx,vue,ts,tsx} && prettier --write packages/**/*.{js,jsx,vue,ts,tsx}",
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs"
"docs:preview": "vitepress preview docs",
"test": "vitest"
},
"dependencies": {
"@element-plus/icons-vue": "^2.0.10",
Expand Down Expand Up @@ -50,6 +51,7 @@
"@vitejs/plugin-vue-jsx": "^3.0.0",
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.2",
"@vue/test-utils": "^2.4.6",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
Expand All @@ -68,6 +70,7 @@
"vite-plugin-externals": "^0.6.2",
"vite-plugin-windicss": "^1.8.10",
"vitepress": "^1.1.3",
"vitest": "^1.6.0",
"vue-tsc": "^1.0.9"
},
"husky": {
Expand All @@ -83,4 +86,4 @@
"yarn lint"
]
}
}
}
Empty file added tests/unit/form.spec.ts
Empty file.
Empty file added tests/unit/table.spec.ts
Empty file.
Empty file added tests/unit/util.spec.ts
Empty file.
43 changes: 43 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// vitest.config.ts Vitest测试框架的配置文件
import { resolve } from 'path'
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
// 测试环境配置
test: {
// 指定测试环境,例如使用happy-dom作为DOM环境
// 相比于 jsdom,Happy DOM 设计得更加轻量级,旨在提供更快的启动时间和运行速度。
environment: 'happy-dom',

// 全局变量配置
globals: true,

// 测试文件匹配模式
include: ['**/__tests__/*.test.{ts,tsx}', '**/?(*.)+(spec|test).{ts,tsx}'],

// 覆盖默认的测试报告处理器
reporters: 'default',

// 收集代码覆盖率
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html']
}
},

// 测试服务器配置,如端口号、代理等
server: {
port: 3000
},
resolve: {
alias: {
'@': resolve('src')
}
},
// 插件配置
plugins: [
vue()
// 可以在这里引入并配置Vitest的插件
]
})
Loading

0 comments on commit 522d162

Please sign in to comment.