Skip to content

Commit 4885604

Browse files
authored
Merge pull request #4 from coderYarn/main
Update jest script
2 parents 90408cf + 0146442 commit 4885604

Some content is hidden

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

86 files changed

+396
-140
lines changed

README.md

+18-1

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"description": "Unitify 是移动端组件库 Vant 的 Uniapp & Taro Vue3 版本,两者基于相同的视觉规范,提供一致的 API 接口,助力开发者快速搭建小程序应用。",
55
"main": "index.js",
66
"dependencies": {
7-
"mime-types": "^2.1.35",
8-
"typescript": "^4.6.3",
9-
"multicast-dns-service-types": "^1.1.0",
10-
"eslint-scope": "^4.0.3"
7+
"typescript": "^4.6.3"
8+
},
9+
"devDependencies": {
10+
1111
},
12-
"devDependencies": {},
1312
"scripts": {
14-
"develop": "pnpm dev -r"
13+
"develop": "pnpm dev -r",
14+
"lint": "eslint src/**/*.{js,vue,ts} --fix",
15+
"lint:create": "eslint --init"
1516
},
1617
"repository": {
1718
"type": "git",

packages/core/.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
3+
}

packages/core/.eslintrc.js

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
parser: "vue-eslint-parser",
7+
globals: {
8+
defineProps: "readonly",
9+
defineEmits: "readonly",
10+
defineExpose: "readonly",
11+
withDefaults: "readonly",
12+
},
13+
extends: [
14+
"eslint:recommended",
15+
"plugin:vue/vue3-recommended",
16+
"plugin:vue/essential",
17+
"plugin:@typescript-eslint/recommended",
18+
],
19+
parserOptions: {
20+
ecmaVersion: "2018",
21+
parser: "@typescript-eslint/parser",
22+
sourceType: "module",
23+
},
24+
plugins: ["vue", "@typescript-eslint"],
25+
rules: {
26+
"vue/script-setup-uses-vars": "error",
27+
indent: ["error", 2],
28+
"linebreak-style": ["error", "windows"],
29+
quotes: ["error", "single"],
30+
semi: ["error", "never"],
31+
"object-shorthand": ["error", "always"],
32+
"array-bracket-spacing": [
33+
"error",
34+
"always",
35+
{
36+
objectsInArrays: false,
37+
arraysInArrays: false,
38+
},
39+
],
40+
"array-callback-return": "error",
41+
"arrow-spacing": "error",
42+
"block-scoped-var": "error",
43+
"block-spacing": "error",
44+
"brace-style": ["error", "1tbs", { allowSingleLine: true }],
45+
camelcase: "error",
46+
"comma-spacing": ["error", { before: false, after: true }],
47+
"comma-style": ["error", "last"],
48+
"computed-property-spacing": ["error", "never"],
49+
"consistent-this": ["error", "that"],
50+
"constructor-super": "error",
51+
curly: "error",
52+
"default-case": "error",
53+
"dot-location": ["error", "property"],
54+
"dot-notation": "error",
55+
"eol-last": ["error", "always"],
56+
eqeqeq: ["error", "always"],
57+
"for-direction": "warn",
58+
"func-call-spacing": ["error", "never"],
59+
"func-names": ["warn", "as-needed"],
60+
"function-paren-newline": ["error", { minItems: 4 }],
61+
"getter-return": ["error", { allowImplicit: true }],
62+
"guard-for-in": "warn",
63+
"implicit-arrow-linebreak": ["warn", "beside"],
64+
"jsx-quotes": ["error", "prefer-single"],
65+
"key-spacing": [
66+
"error",
67+
{
68+
beforeColon: false,
69+
align: "colon",
70+
},
71+
],
72+
"keyword-spacing": [
73+
"error",
74+
{
75+
before: true,
76+
after: true,
77+
},
78+
],
79+
"lines-around-comment": ["warn", { beforeBlockComment: true }],
80+
"new-cap": "warn",
81+
"no-await-in-loop": "error",
82+
"no-buffer-constructor": "error",
83+
"no-cond-assign": "error",
84+
"no-empty": "warn",
85+
"no-constant-condition": "warn",
86+
"vue/no-multiple-template-root": "off",
87+
parser: "vue-eslint-parser",
88+
},
89+
};

packages/core/.pnpm-debug.log

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"0 debug pnpm:scope": {
3+
"selected": 1,
4+
"workspacePrefix": "D:\\web\\vue\\unitify"
5+
},
6+
"1 error pnpm": {
7+
"fileName": "D:\\web\\vue\\unitify\\packages\\core\\package.json",
8+
"codeFrame": "\u001b[0m \u001b[90m 5 |\u001b[39m \u001b[32m\"scripts\"\u001b[39m\u001b[33m:\u001b[39m {\u001b[0m\n\u001b[0m \u001b[90m 6 |\u001b[39m \u001b[32m\"jest\"\u001b[39m\u001b[33m:\u001b[39m \u001b[32m\"jest --watch\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 7 |\u001b[39m }\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 8 |\u001b[39m \u001b[32m\"keywords\"\u001b[39m\u001b[33m:\u001b[39m [\u001b[0m\n\u001b[0m \u001b[90m 9 |\u001b[39m \u001b[32m\"unitify\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 10 |\u001b[39m \u001b[32m\"unitify-ui\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m",
9+
"code": "ERR_PNPM_JSON_PARSE",
10+
"err": {
11+
"name": "pnpm",
12+
"message": "Unexpected token \"}\" (0x7D) in JSON at position 125 while parsing near \"...\\\"jest --watch\\\",\\r\\n },\\r\\n \\\"keywords\\\": [\\r...\" in D:\\web\\vue\\unitify\\packages\\core\\package.json \n\n\u001b[0m \u001b[90m 5 |\u001b[39m \u001b[32m\"scripts\"\u001b[39m\u001b[33m:\u001b[39m {\u001b[0m\n\u001b[0m \u001b[90m 6 |\u001b[39m \u001b[32m\"jest\"\u001b[39m\u001b[33m:\u001b[39m \u001b[32m\"jest --watch\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 7 |\u001b[39m }\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 8 |\u001b[39m \u001b[32m\"keywords\"\u001b[39m\u001b[33m:\u001b[39m [\u001b[0m\n\u001b[0m \u001b[90m 9 |\u001b[39m \u001b[32m\"unitify\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 10 |\u001b[39m \u001b[32m\"unitify-ui\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n",
13+
"code": "ERR_PNPM_JSON_PARSE",
14+
"stack": "pnpm: Unexpected token \"}\" (0x7D) in JSON at position 125 while parsing near \"...\\\"jest --watch\\\",\\r\\n },\\r\\n \\\"keywords\\\": [\\r...\" in D:\\web\\vue\\unitify\\packages\\core\\package.json \n\n\u001b[0m \u001b[90m 5 |\u001b[39m \u001b[32m\"scripts\"\u001b[39m\u001b[33m:\u001b[39m {\u001b[0m\n\u001b[0m \u001b[90m 6 |\u001b[39m \u001b[32m\"jest\"\u001b[39m\u001b[33m:\u001b[39m \u001b[32m\"jest --watch\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m\u001b[31m\u001b[1m>\u001b[22m\u001b[39m\u001b[90m 7 |\u001b[39m }\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m |\u001b[39m \u001b[31m\u001b[1m^\u001b[22m\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 8 |\u001b[39m \u001b[32m\"keywords\"\u001b[39m\u001b[33m:\u001b[39m [\u001b[0m\n\u001b[0m \u001b[90m 9 |\u001b[39m \u001b[32m\"unitify\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\u001b[0m \u001b[90m 10 |\u001b[39m \u001b[32m\"unitify-ui\"\u001b[39m\u001b[33m,\u001b[39m\u001b[0m\n\n at parseJson (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:3133:27)\n at readJsonFile (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:19780:42)\n at async tryReadProjectManifest (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:19841:32)\n at async readProjectManifest (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:19826:23)\n at async Object.readProjectManifestOnly (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:19834:28)\n at async readProjectManifestOnly (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:43827:24)\n at async Object.handler (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:178338:24)\n at async C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:182614:21\n at async run (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:182588:34)\n at async runPnpm (C:\\Users\\coder\\AppData\\Roaming\\npm\\pnpm-global\\5\\node_modules\\.pnpm\\[email protected]\\node_modules\\pnpm\\dist\\pnpm.cjs:182807:5)"
15+
}
16+
}
17+
}

packages/core/README.md

+16

packages/core/babel.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
 "presets": [
3+
  ["@babel/preset-env"],
4+
   "@babel/preset-typescript"
5+
],
6+
"plugins": ["@babel/plugin-transform-runtime"]
7+
}
8+

packages/core/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

packages/core/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { App } from "vue";
2-
import { Button } from "./components/button";
3-
import Avatar from "./components/avatar/avatar.vue";
4-
import { Icon } from "./components/icon";
5-
import { Tab, Tabs } from "./components/tabs";
6-
import { Swiper, SwiperItem } from "./components/swiper";
7-
import { FlexItem, Flex } from "./components/flex";
8-
import { Image } from "./components/image";
9-
import { Cell ,CellGroup} from "./components/cell";
2+
import { Button } from "./src/components/button";
3+
import Avatar from "./src/components/avatar/avatar.vue";
4+
import { Icon } from "./src/components/icon";
5+
import { Tab, Tabs } from "./src/components/tabs";
6+
import { Swiper, SwiperItem } from "./src/components/swiper";
7+
import { FlexItem, Flex } from "./src/components/flex";
8+
import { Image } from "./src/components/image";
9+
import { Cell, CellGroup } from "./src/components/cell";
1010
// 所有组件列表
1111
const components = [
1212
Button,
@@ -20,7 +20,7 @@ const components = [
2020
Flex,
2121
Image,
2222
Cell,
23-
CellGroup
23+
CellGroup,
2424
];
2525

2626
// 定义 install 方法, App 作为参数
@@ -41,7 +41,7 @@ export {
4141
Flex,
4242
Image,
4343
Cell,
44-
CellGroup
44+
CellGroup,
4545
};
4646

4747
export default {

packages/core/jest.config.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
rootDir: path.resolve(__dirname),
5+
clearMocks: true,
6+
coverageDirectory: "coverage",
7+
coverageProvider: "v8",
8+
moduleFileExtensions: ["vue", "js", "json", "jsx", "ts", "tsx", "node"],
9+
// 别名设置
10+
moduleNameMapper: {
11+
"@/(.*)$": "<rootDir>/src/components/$1",
12+
},
13+
preset: "ts-jest",
14+
testEnvironment: "jsdom",
15+
// 测试文件
16+
testMatch: ["<rootDir>/src/components/**/__tests__/**/*.spec.(ts|tsx|js)"],
17+
testPathIgnorePatterns: ["/node_modules/"],
18+
moduleFileExtensions: ["js", "json", "ts", "tsx"],
19+
20+
transform: {
21+
"^.+\\.vue$": "vue-jest",
22+
"^.+\\.(ts|tsx|js|jsx)$": [
23+
"babel-jest",
24+
{
25+
presets: [
26+
["@babel/preset-env", { targets: { node: "current" } }],
27+
["@babel/preset-typescript"],
28+
],
29+
plugins: ["@vue/babel-plugin-jsx"],
30+
},
31+
],
32+
},
33+
};

packages/core/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createApp } from 'vue'
2+
import App from './App.vue'
3+
4+
createApp(App).mount('#app')

packages/core/package.json

+36-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
{
2-
"name": "@unitify/~core",
3-
"version": "0.1.0",
4-
"description": "",
5-
"scripts": {},
6-
"keywords": [
7-
"unitify",
8-
"unitify-ui",
9-
"ui",
10-
"uni-app"
11-
12-
],
13-
"author": "",
14-
"license": "MIT"
15-
}
2+
"name": "@unitify/core",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vue-tsc --noEmit && vite build",
8+
"preview": "vite preview",
9+
"lint": "eslint src/**/*.{js,vue,ts} --fix",
10+
"lint:create": "eslint --init",
11+
"test": "jest"
12+
},
13+
"dependencies": {
14+
"vue": "^3.2.25"
15+
},
16+
"devDependencies": {
17+
"@babel/core": "^7.17.9",
18+
"@babel/preset-env": "^7.16.11",
19+
"@babel/preset-typescript": "^7.16.7",
20+
"@testing-library/jest-dom": "^5.16.4",
21+
"@types/jest": "^27.4.1",
22+
"@typescript-eslint/eslint-plugin": "^5.20.0",
23+
"@typescript-eslint/parser": "^5.20.0",
24+
"@vitejs/plugin-vue": "^2.3.1",
25+
"@vue/babel-plugin-jsx": "^1.1.1",
26+
"@vue/test-utils": "^2.0.0-rc.18",
27+
"babel-jest": "26.0.0",
28+
"eslint": "^8.13.0",
29+
"eslint-plugin-vue": "^8.7.1",
30+
"jest": "26.0.0",
31+
"ts-jest": "26.4.4",
32+
"typescript": "^4.5.4",
33+
"vite": "^2.9.5",
34+
"vue-jest": "^5.0.0-alpha.10",
35+
"vue-tsc": "^0.34.7"
36+
}
37+
}

packages/core/src/App.vue

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<script setup lang="ts">
2+
// This starter template is using Vue 3 <script setup> SFCs
3+
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
4+
import HelloWorld from './components/HelloWorld.vue'
5+
</script>
6+
7+
<template>
8+
<img alt="Vue logo" src="./assets/logo.png" />
9+
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite" />
10+
</template>
11+
12+
<style>
13+
#app {
14+
font-family: Avenir, Helvetica, Arial, sans-serif;
15+
-webkit-font-smoothing: antialiased;
16+
-moz-osx-font-smoothing: grayscale;
17+
text-align: center;
18+
color: #2c3e50;
19+
margin-top: 60px;
20+
}
21+
</style>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div>
3+
<h1>{{ msg }}</h1>
4+
</div>
5+
</template>
6+
7+
<script lang="ts">
8+
export default {
9+
name: 'HelloWorld',
10+
data() {
11+
return {
12+
msg: 'Hello Jest',
13+
};
14+
},
15+
};
16+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { mount } from "@vue/test-utils";
2+
import Hello from "../helloWorld.vue";
3+
4+
it('content', () => {
5+
const Comp = {
6+
template: `<div><Hello /></div>`
7+
}
8+
const wrapper = mount(Comp, {
9+
global: {
10+
components: {
11+
Hello
12+
}
13+
}
14+
})
15+
// 最简单的测试用例查看是否包含Hello Jest文字。
16+
expect(wrapper.findComponent({ name: 'HelloWorld' }).text()).toContain('Hello Jest')
17+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const add = (a: number, b: number) => a + b

0 commit comments

Comments
 (0)