Jelajahi Sumber

♻️ refactor(config): update jest module mapping configuration
- 修复拼写错误,将shared重命名为share以保持一致性
- 修正moduleNameMapping为正确的jest配置属性名

📦 build(deps): add ts-jest-mock-import-meta dependency

✅ test(test): add basic jest test file to verify configuration

🔧 chore(scripts): fix indentation in db:migrate script command

yourname 2 bulan lalu
induk
melakukan
26580ff2fc
4 mengubah file dengan 30 tambahan dan 4 penghapusan
  1. 2 2
      jest.config.js
  2. 3 2
      package.json
  3. 12 0
      pnpm-lock.yaml
  4. 13 0
      src/test/basic.test.ts

+ 2 - 2
jest.config.js

@@ -10,11 +10,11 @@ const config = {
   ],
 
   // 模块名称映射
-  moduleNameMapping: {
+  moduleNameMapper: {
     '^@/(.*)$': '<rootDir>/src/$1',
     '^@/client/(.*)$': '<rootDir>/src/client/$1',
     '^@/server/(.*)$': '<rootDir>/src/server/$1',
-    '^@/shared/(.*)$': '<rootDir>/src/shared/$1',
+    '^@/share/(.*)$': '<rootDir>/src/share/$1',
     '^@/test/(.*)$': '<rootDir>/test/$1'
   },
 

+ 3 - 2
package.json

@@ -14,7 +14,7 @@
     "test:watch": "jest --watch",
     "test:ui": "jest src/client/__tests__",
     "test:api": "jest src/server/__tests__",
-   "db:migrate": "tsx scripts/migrate.ts",
+    "db:migrate": "tsx scripts/migrate.ts",
     "db:seed": "tsx scripts/seed.ts",
     "db:reset": "tsx scripts/reset-db.ts",
     "lint": "eslint . --ext .ts,.tsx",
@@ -106,8 +106,9 @@
     "cross-env": "^7.0.3",
     "jest": "^29.7.0",
     "jest-environment-jsdom": "^29.7.0",
-    "ts-jest": "^29.2.5",
     "tailwindcss": "^4.1.11",
+    "ts-jest": "^29.2.5",
+    "ts-jest-mock-import-meta": "^1.3.1",
     "tsx": "^4.20.3",
     "typescript": "~5.8.3",
     "vite": "^7.0.0",

+ 12 - 0
pnpm-lock.yaml

@@ -261,6 +261,9 @@ importers:
       ts-jest:
         specifier: ^29.2.5
         version: 29.4.1(@babel/core@7.28.4)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.4))(jest-util@29.7.0)(jest@29.7.0(@types/node@24.1.0))(typescript@5.8.3)
+      ts-jest-mock-import-meta:
+        specifier: ^1.3.1
+        version: 1.3.1(ts-jest@29.4.1(@babel/core@7.28.4)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.4))(jest-util@29.7.0)(jest@29.7.0(@types/node@24.1.0))(typescript@5.8.3))
       tsx:
         specifier: ^4.20.3
         version: 4.20.3
@@ -3584,6 +3587,11 @@ packages:
     resolution: {integrity: sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==}
     engines: {node: '>=12'}
 
+  ts-jest-mock-import-meta@1.3.1:
+    resolution: {integrity: sha512-KGrp9Nh/SdyrQs5hZvtkp0CFPOgAh3DL57NZgFRbtlvMyEo7XuXLbeyylmxFZGGu30pL338h9KxwSxrNDndygw==}
+    peerDependencies:
+      ts-jest: '>=20.0.0'
+
   ts-jest@29.4.1:
     resolution: {integrity: sha512-SaeUtjfpg9Uqu8IbeDKtdaS0g8lS6FT6OzM3ezrDfErPJPHNDo/Ey+VFGP1bQIDfagYDLyRpd7O15XpG1Es2Uw==}
     engines: {node: ^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0}
@@ -7357,6 +7365,10 @@ snapshots:
     dependencies:
       punycode: 2.3.1
 
+  ts-jest-mock-import-meta@1.3.1(ts-jest@29.4.1(@babel/core@7.28.4)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.4))(jest-util@29.7.0)(jest@29.7.0(@types/node@24.1.0))(typescript@5.8.3)):
+    dependencies:
+      ts-jest: 29.4.1(@babel/core@7.28.4)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.4))(jest-util@29.7.0)(jest@29.7.0(@types/node@24.1.0))(typescript@5.8.3)
+
   ts-jest@29.4.1(@babel/core@7.28.4)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.4))(jest-util@29.7.0)(jest@29.7.0(@types/node@24.1.0))(typescript@5.8.3):
     dependencies:
       bs-logger: 0.2.6

+ 13 - 0
src/test/basic.test.ts

@@ -0,0 +1,13 @@
+// 基本测试来验证Jest配置
+
+describe('Basic Jest Test', () => {
+  it('should work', () => {
+    expect(1 + 1).toBe(2);
+  });
+
+  it('should support module mapping', () => {
+    // 测试模块映射
+    const testUtil = jest.fn();
+    expect(testUtil).toBeDefined();
+  });
+});