diff --git a/.eslintrc.js b/.eslintrc.js index bc75953..12aca84 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1 +1,9 @@ -module.exports = require('@lobehub/lint').eslint; +const config = require('@lobehub/lint').eslint; + +module.exports = { + ...config, + rules: { + ...config.rules, + 'unicorn/prefer-string-replace-all': 0, + }, +}; diff --git a/.fatherrc.ts b/.fatherrc.ts index 4b817e0..ea90a40 100644 --- a/.fatherrc.ts +++ b/.fatherrc.ts @@ -1,4 +1,5 @@ import { defineConfig } from 'father'; +import { resolve } from 'node:path'; export default defineConfig({ plugins: ['father-plugin-dumi-theme'], diff --git a/example/.dumirc.ts b/example/.dumirc.ts index 5e0d99e..d1069e4 100644 --- a/example/.dumirc.ts +++ b/example/.dumirc.ts @@ -1,5 +1,5 @@ import { defineConfig } from 'dumi'; -import path from 'node:path'; +import { resolve } from 'node:path'; import { homepage, name } from '../package.json'; @@ -58,8 +58,8 @@ const themeConfig = { export default defineConfig({ alias: { - '@': path.join(__dirname, '../src'), - 'dumi-theme-lobehub': path.join(__dirname, '../src'), + '@': resolve(__dirname, 'src'), + 'dumi-theme-lobehub': resolve(__dirname, '../src'), }, codeSplitting: { jsStrategy: 'granularChunks', diff --git a/package.json b/package.json index 9182f59..9b76dd3 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "scripts": { "build": "father build", "build:docs": "npm run build && npm run build --prefix=example", - "ci": "npm run test", + "ci": "npm run lint && npm run type-check && npm run test", "dev": "father dev", "dev:docs": "npm run start --prefix=example", "lint": "eslint \"{src,example}/**/*.{js,jsx,ts,tsx}\" --fix", @@ -38,7 +38,9 @@ "prettier": "prettier -c --write --no-error-on-unmatched-pattern \"**/**\"", "release": "semantic-release", "start": "concurrently \"npm run dev\" \"npm run dev:docs\"", - "test": "npm run type-check && npm run lint", + "test": "vitest --passWithNoTests", + "test:coverage": "vitest run --coverage --passWithNoTests", + "test:update": "vitest -u", "type-check": "tsc -p tsconfig-check.json" }, "lint-staged": { @@ -69,7 +71,6 @@ "antd-style": "^3", "chalk": "^4", "fast-deep-equal": "^3", - "history": "^5", "lodash-es": "^4", "lucide-react": "latest", "polished": "^4", @@ -86,6 +87,7 @@ "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "@vitest/coverage-c8": "latest", "antd-style": "^3", "commitlint": "^17", "concurrently": "^8", @@ -94,7 +96,9 @@ "eslint": "^8", "father": "^4", "father-plugin-dumi-theme": "latest", + "history": "^5", "husky": "^8", + "jsdom": "^22", "leva": "^0", "lint-staged": "^13", "prettier": "^2", @@ -104,7 +108,8 @@ "remark-cli": "^11", "semantic-release": "^21", "stylelint": "^15", - "typescript": "^5" + "typescript": "^5", + "vitest": "latest" }, "peerDependencies": { "antd": ">=5", diff --git a/src/builtins/Container/style.ts b/src/builtins/Container/style.ts index 0b0bdc9..ba2fc48 100644 --- a/src/builtins/Container/style.ts +++ b/src/builtins/Container/style.ts @@ -1,7 +1,7 @@ import { FullToken, createStyles } from 'antd-style'; const toCamelCase = (string_: string) => { - return string_.replaceAll(/( |^)[a-z]/g, (L) => L.toUpperCase()); + return string_.replace(/( |^)[a-z]/g, (L) => L.toUpperCase()); }; export const useStyles = createStyles(({ token, prefixCls, css }) => { // 把首字母大写 diff --git a/tests/test-setup.ts b/tests/test-setup.ts new file mode 100644 index 0000000..e69de29 diff --git a/tsconfig.json b/tsconfig.json index 9e97279..a918474 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,12 @@ { "compilerOptions": { - "target": "esnext", - "module": "esnext", "strict": true, "declaration": true, - "downlevelIteration": true, "skipLibCheck": true, "esModuleInterop": true, - "moduleResolution": "node", "resolveJsonModule": true, "jsx": "react-jsx", + "types": ["vitest/globals"], "baseUrl": ".", "paths": { "@@/*": ["example/.dumi/tmp/*"], diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..8c53749 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,21 @@ +import { defineConfig } from 'vitest/config'; + +import { name } from './package.json'; + +export default defineConfig({ + esbuild: { + jsxInject: "import React from 'react'", + }, + test: { + alias: { + '@': './src', + [name]: './src', + }, + coverage: { + reporter: ['text', 'text-summary', 'json', 'lcov'], + }, + environment: 'jsdom', + globals: true, + setupFiles: './tests/test-setup.ts', + }, +});