vitest-environment-uniapp 0.0.3 → 0.0.5

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
@@ -10,6 +10,7 @@
10
10
  > [!IMPORTANT]
11
11
  > 该项目依赖 `@dcloudio/uni-automator` 必须安装
12
12
  > h5 平台下,需要安装 `playwright` ; 但目前无法获取启动状态导致超时
13
+ >
13
14
  > environmentOptions 参数同 [uni-app 官方文档](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs) , 但官网长久未更新,导致参数与实际不符
14
15
 
15
16
  ## 安装
@@ -40,16 +41,12 @@ export default defineConfig({
40
41
  test: {
41
42
  environment: 'uniapp',
42
43
  environmentOptions: {
43
- compile: true,
44
- platform: 'h5', // 测试平台
45
- projectPath: './src', // manifest.json 所在目录
46
- port: 5121,
47
- h5: {
48
- url: 'http://localhost:5180/', // 改成你的 H5 服务器地址
49
- options: {
50
- headless: false, // 是否无头模式
51
- },
52
- },
44
+ uniapp: {
45
+ compile: true,
46
+ platform: 'mp-weixin',
47
+ projectPath: './src',
48
+ port: 5121,
49
+ }
53
50
  },
54
51
  },
55
52
  })
package/dist/index.d.mts CHANGED
@@ -14,7 +14,9 @@ declare class UniAppEnvironment implements Environment {
14
14
  viteEnvironment: string;
15
15
  private TIME_TEARDOWN;
16
16
  private _store;
17
- setup(global: Global, options: UniInitOptions): Promise<{
17
+ setup(global: Global, options: {
18
+ uniapp?: UniInitOptions;
19
+ }): Promise<{
18
20
  teardown: (global: Global) => Promise<void>;
19
21
  }>;
20
22
  }
package/dist/index.mjs CHANGED
@@ -9,15 +9,16 @@ var UniAppEnvironment = class {
9
9
  TIME_TEARDOWN = 3e3;
10
10
  _store = { init: false };
11
11
  async setup(global, options) {
12
+ const uniappOptions = options?.uniapp;
12
13
  if (this._store.init) {
13
14
  if (!global.program) throw new Error("测试环境初始化失败,请重新运行测试");
14
15
  } else try {
15
- const platform = options?.platform || process.env.UNI_PLATFORM;
16
+ const platform = uniappOptions?.platform || process.env.UNI_PLATFORM;
16
17
  const program = await new Automator().launch({
17
- ...options,
18
+ ...uniappOptions,
18
19
  platform
19
20
  });
20
- if (options?.devtools?.remote) await program.remote(true);
21
+ if (uniappOptions?.devtools?.remote) await program.remote(true);
21
22
  const uni = initUni(program);
22
23
  this._store.uni = uni;
23
24
  this._store.program = program;
package/global.d.ts CHANGED
@@ -1,3 +1,33 @@
1
+ import 'vitest/node'
2
+
3
+ type RecordUnknown = Record<string, unknown>
4
+
5
+ declare module 'vitest/node' {
6
+ interface EnvironmentOptions {
7
+ /**
8
+ * uniapp 测试环境选项,详情请参考[uni-app 自动化测试](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs)
9
+ */
10
+ uniapp?: Partial<RecordUnknown & {
11
+ /**
12
+ * H5 测试选项
13
+ */
14
+ 'h5': RecordUnknown
15
+ /**
16
+ * app-plus 测试选项, 需要安装 HBuilderX
17
+ */
18
+ 'app-plus': RecordUnknown
19
+ /**
20
+ * 微信小程序测试选项
21
+ */
22
+ 'mp-weixin': RecordUnknown
23
+ /**
24
+ * 百度小程序测试选项
25
+ */
26
+ 'mp-baidu': RecordUnknown
27
+ }>
28
+ }
29
+ }
30
+
1
31
  declare global {
2
32
  /**
3
33
  * Element 模块提供了控制页面元素的方法
@@ -442,4 +472,3 @@ declare global {
442
472
  exposeFunction: (name: string, bindingFunction: (() => unknown)) => Promise<void>
443
473
  }
444
474
  }
445
- export {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest-environment-uniapp",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.5",
5
5
  "description": "Vitest environment for UniApp",
6
6
  "author": "FliPPeDround <flippedround@qq.com>",
7
7
  "license": "MIT",
@@ -28,6 +28,10 @@
28
28
  "dist",
29
29
  "global.d.ts"
30
30
  ],
31
+ "peerDependencies": {
32
+ "@dcloudio/uni-automator": "*",
33
+ "vitest": "*"
34
+ },
31
35
  "devDependencies": {
32
36
  "@antfu/eslint-config": "^6.6.1",
33
37
  "@antfu/ni": "^28.0.0",