@wevu/api 0.2.18 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,3 +28,27 @@ import { createWeapi, wpi } from '@wevu/api'
28
28
  ```
29
29
 
30
30
  `@wevu/api` 不再维护独立实现,所有能力、平台适配、类型声明与兼容性修复均由 `@weapp-core/api` 提供。
31
+
32
+ ## Vitest mock
33
+
34
+ 兼容入口提供同一套类型安全 mock。Vitest 配置使用对应 setup 子路径:
35
+
36
+ ```ts
37
+ import { defineConfig } from 'vitest/config'
38
+
39
+ export default defineConfig({
40
+ test: {
41
+ setupFiles: ['@wevu/api/vitest/setup'],
42
+ },
43
+ })
44
+ ```
45
+
46
+ ```ts
47
+ import { wpiMock } from '@wevu/api/vitest'
48
+
49
+ wpiMock.request.mockResolvedValue(responseFixture)
50
+ ```
51
+
52
+ `@wevu/api/vitest/setup` 会同时替换 `@weapp-core/api` 与 `@wevu/api` 导入的 `api` / `wpi`,两层入口共享同一单例。也可以使用 `createApiMock()` / `createWpiMock()` 创建隔离实例,或用 `resetApiMock()` 手动重置指定实例。
53
+
54
+ 该能力只 mock API 门面;页面、组件、WXML 与宿主运行时行为仍由 `@mpcore/test` 覆盖。
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,5 @@
1
+ import { setupApiMock } from "@weapp-core/api/vitest";
2
+ //#region src/vitestSetup.ts
3
+ setupApiMock(["@weapp-core/api", "@wevu/api"]);
4
+ //#endregion
5
+ export {};
@@ -0,0 +1 @@
1
+ export * from "@weapp-core/api/vitest";
@@ -0,0 +1,2 @@
1
+ export * from "@weapp-core/api/vitest";
2
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/api",
3
3
  "type": "module",
4
- "version": "0.2.18",
4
+ "version": "0.3.0",
5
5
  "description": "Compatibility entry for @weapp-core/api",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -14,7 +14,9 @@
14
14
  "url": "https://github.com/weapp-vite/weapp-vite/issues"
15
15
  },
16
16
  "keywords": [],
17
- "sideEffects": false,
17
+ "sideEffects": [
18
+ "./dist/vitest/setup.mjs"
19
+ ],
18
20
  "exports": {
19
21
  ".": {
20
22
  "types": "./types/index.d.ts",
@@ -22,6 +24,14 @@
22
24
  "types": "./types/index.d.ts",
23
25
  "default": "./dist/index.mjs"
24
26
  }
27
+ },
28
+ "./vitest": {
29
+ "types": "./dist/vitest.d.mts",
30
+ "import": "./dist/vitest.mjs"
31
+ },
32
+ "./vitest/setup": {
33
+ "types": "./dist/vitest/setup.d.mts",
34
+ "import": "./dist/vitest/setup.mjs"
25
35
  }
26
36
  },
27
37
  "main": "./dist/index.mjs",
@@ -31,8 +41,23 @@
31
41
  "dist",
32
42
  "types"
33
43
  ],
44
+ "peerDependencies": {
45
+ "vitest": ">=4.0.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "vitest": {
49
+ "optional": true
50
+ }
51
+ },
34
52
  "dependencies": {
35
- "@weapp-core/api": "0.2.0"
53
+ "@weapp-core/api": "0.3.0"
54
+ },
55
+ "tsd": {
56
+ "compilerOptions": {
57
+ "module": "NodeNext",
58
+ "moduleResolution": "NodeNext",
59
+ "paths": {}
60
+ }
36
61
  },
37
62
  "publishConfig": {
38
63
  "access": "public"