diff --git a/.eslintrc.js b/.eslintrc.js index 09aff820a6a92110166dceb5d4b858e0f5d14d23..d4c9c6cbbe49453de8f6d7e1d3c5f922bb56b144 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,6 +22,7 @@ module.exports = defineConfig({ 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended', + 'plugin:jest/recommended', ], rules: { '@typescript-eslint/ban-ts-ignore': 'off', diff --git a/.gitignore b/.gitignore index 600565c94801bc2d7449d277455a33c63b4308d8..2f4e661106807de4857577577a4bd43ecde460da 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ test/server/static # local env files .env.local .env.*.local +.eslintcache # Log files npm-debug.log* diff --git a/CHANGELOG.zh_CN.md b/CHANGELOG.zh_CN.md index b471c1366b27fe515716ad6b02671e3901ad8504..61fa41798a82d48d54e213d315f24951fb64866b 100644 --- a/CHANGELOG.zh_CN.md +++ b/CHANGELOG.zh_CN.md @@ -15,6 +15,7 @@ - **Drawer** `useDrawer`新增`closeDrawer`函数 - **Preview** 新增`createImgPreview`图片预览函数 - **Setup** 新增引导页示例 +- **Tests** 添加 jest 测试套件,暂不支持 Vue 组件单测 ### 🐛 Bug Fixes diff --git a/jest.config.mjs b/jest.config.mjs new file mode 100644 index 0000000000000000000000000000000000000000..53091ac3cfc997f4cb5217fed6d1265c9584db5d --- /dev/null +++ b/jest.config.mjs @@ -0,0 +1,37 @@ +export default { + preset: 'ts-jest', + roots: ['/tests/'], + clearMocks: true, + moduleDirectories: ['node_modules', 'src'], + moduleFileExtensions: ['js', 'ts', 'vue', 'tsx', 'jsx', 'json', 'node'], + modulePaths: ['/src', '/node_modules'], + testMatch: [ + '**/tests/**/*.[jt]s?(x)', + '**/?(*.)+(spec|test).[tj]s?(x)', + '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$', + ], + testPathIgnorePatterns: [ + '/tests/server/', + '/tests/__mocks__/', + '/node_modules/', + ], + transform: { + '^.+\\.tsx?$': 'ts-jest', + '^.+\\.(vue)$': 'vue-jest', + }, + transformIgnorePatterns: ['/tests/__mocks__/', '/node_modules/'], + // A map from regular expressions to module names that allow to stub out resources with a single module + moduleNameMapper: { + '\\.(vs|fs|vert|frag|glsl|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': + '/tests/__mocks__/fileMock.ts', + '\\.(sass|s?css|less)$': '/tests/__mocks__/styleMock.ts', + '\\?worker$': '/tests/__mocks__/workerMock.ts', + '^/@/(.*)$': '/src/$1', + }, + testEnvironment: 'jsdom', + verbose: true, + collectCoverage: false, + coverageDirectory: 'coverage', + collectCoverageFrom: ['src/**/*.{js,ts,vue}'], + coveragePathIgnorePatterns: ['^.+\\.d\\.ts$'], +}; diff --git a/package.json b/package.json index 9e90a16213a4070d872f9e138372435a04ca8587..e0cacaf29a67b0b369888842a0a0f6835ace5834 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,13 @@ "log": "conventional-changelog -p angular -i CHANGELOG.md -s", "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite", "clean:lib": "rimraf node_modules", - "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix", + "lint:eslint": "eslint --cache --max-warnings 0 \"{src,mock}/**/*.{vue,ts,tsx}\" --fix", "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"", - "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", + "lint:stylelint": "stylelint --cache --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", "lint:lint-staged": "lint-staged -c ./.husky/lintstagedrc.js", "lint:pretty": "pretty-quick --staged", + "test:unit": "jest", + "test:unit-coverage": "jest --coverage", "test:gzip": "http-server dist --cors --gzip -c-1", "test:br": "http-server dist --cors --brotli -c-1", "reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap", @@ -71,6 +73,7 @@ "@types/fs-extra": "^9.0.11", "@types/inquirer": "^7.3.1", "@types/intro.js": "^3.0.1", + "@types/jest": "^26.0.23", "@types/lodash-es": "^4.17.4", "@types/mockjs": "^1.0.3", "@types/node": "^15.12.2", @@ -84,7 +87,9 @@ "@vitejs/plugin-vue": "^1.2.3", "@vitejs/plugin-vue-jsx": "^1.1.5", "@vue/compiler-sfc": "3.0.11", + "@vue/test-utils": "^2.0.0-rc.6", "autoprefixer": "^10.2.6", + "babel-jest": "^27.0.2", "commitizen": "^4.2.4", "conventional-changelog-cli": "^2.1.1", "cross-env": "^7.0.3", @@ -92,6 +97,7 @@ "eslint": "^7.28.0", "eslint-config-prettier": "^8.3.0", "eslint-define-config": "^1.0.8", + "eslint-plugin-jest": "^24.3.6", "eslint-plugin-prettier": "^3.4.0", "eslint-plugin-vue": "^7.11.1", "esno": "^0.7.3", @@ -100,6 +106,7 @@ "husky": "^6.0.0", "inquirer": "^8.1.1", "is-ci": "^3.0.0", + "jest": "^27.0.4", "less": "^4.1.1", "lint-staged": "^11.0.0", "postcss": "^8.3.5", @@ -111,6 +118,7 @@ "stylelint-config-prettier": "^8.0.2", "stylelint-config-standard": "^22.0.0", "stylelint-order": "^4.1.0", + "ts-jest": "^27.0.3", "ts-node": "^10.0.0", "typescript": "4.3.3", "vite": "2.3.7", @@ -125,6 +133,7 @@ "vite-plugin-theme": "^0.8.1", "vite-plugin-windicss": "^1.0.4", "vue-eslint-parser": "^7.6.0", + "vue-jest": "^5.0.0-alpha.10", "vue-tsc": "^0.1.7" }, "resolutions": { diff --git a/src/views/dashboard/workbench/components/DynamicInfo.vue b/src/views/dashboard/workbench/components/DynamicInfo.vue index 659600e07ca06197e7be274a5817d1975d11122a..20b2acb7916fb04138f584bcc3512310f791e9df 100644 --- a/src/views/dashboard/workbench/components/DynamicInfo.vue +++ b/src/views/dashboard/workbench/components/DynamicInfo.vue @@ -10,6 +10,7 @@ +