@wevu/api 0.2.18 → 0.3.1
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 +26 -0
- package/dist/vitest/setup.d.mts +1 -0
- package/dist/vitest/setup.mjs +5 -0
- package/dist/vitest.d.mts +1 -0
- package/dist/vitest.mjs +2 -0
- package/package.json +28 -3
package/README.md
CHANGED
|
@@ -27,4 +27,30 @@ await hostApi.request({
|
|
|
27
27
|
import { createWeapi, wpi } from '@wevu/api'
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
同步直接返回 API(包括部分没有 `Sync` 后缀的宿主 API)会保留原始返回值;异步 API 才会在未传回调时返回 Promise。
|
|
31
|
+
|
|
30
32
|
`@wevu/api` 不再维护独立实现,所有能力、平台适配、类型声明与兼容性修复均由 `@weapp-core/api` 提供。
|
|
33
|
+
|
|
34
|
+
## Vitest mock
|
|
35
|
+
|
|
36
|
+
兼容入口提供同一套类型安全 mock。Vitest 配置使用对应 setup 子路径:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineConfig } from 'vitest/config'
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
test: {
|
|
43
|
+
setupFiles: ['@wevu/api/vitest/setup'],
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { wpiMock } from '@wevu/api/vitest'
|
|
50
|
+
|
|
51
|
+
wpiMock.request.mockResolvedValue(responseFixture)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`@wevu/api/vitest/setup` 会同时替换 `@weapp-core/api` 与 `@wevu/api` 导入的 `api` / `wpi`,两层入口共享同一单例。也可以使用 `createApiMock()` / `createWpiMock()` 创建隔离实例,或用 `resetApiMock()` 手动重置指定实例。
|
|
55
|
+
|
|
56
|
+
该能力只 mock API 门面;页面、组件、WXML 与宿主运行时行为仍由 `@mpcore/test` 覆盖。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@weapp-core/api/vitest";
|
package/dist/vitest.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wevu/api",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.1",
|
|
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":
|
|
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.
|
|
53
|
+
"@weapp-core/api": "0.3.1"
|
|
54
|
+
},
|
|
55
|
+
"tsd": {
|
|
56
|
+
"compilerOptions": {
|
|
57
|
+
"module": "NodeNext",
|
|
58
|
+
"moduleResolution": "NodeNext",
|
|
59
|
+
"paths": {}
|
|
60
|
+
}
|
|
36
61
|
},
|
|
37
62
|
"publishConfig": {
|
|
38
63
|
"access": "public"
|