vitest-environment-uniapp 0.0.2 → 0.0.4

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
@@ -7,10 +7,10 @@
7
7
 
8
8
  # Vitest 的 uni-app e2e 测试环境
9
9
 
10
- ## 已知问题
11
-
12
- - h5 平台下,无法获取启动状态导致超时。
13
- - environmentOptions 参数同 [uni-app 官方文档](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs) , 但官网长久未更新,导致参数与实际不符。
10
+ > [!IMPORTANT]
11
+ > 该项目依赖 `@dcloudio/uni-automator` 必须安装
12
+ > h5 平台下,需要安装 `playwright` ; 但目前无法获取启动状态导致超时
13
+ > environmentOptions 参数同 [uni-app 官方文档](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs) , 但官网长久未更新,导致参数与实际不符
14
14
 
15
15
  ## 安装
16
16
 
@@ -40,16 +40,12 @@ export default defineConfig({
40
40
  test: {
41
41
  environment: 'uniapp',
42
42
  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
- },
43
+ uniapp: {
44
+ compile: true,
45
+ platform: 'mp-weixin',
46
+ projectPath: './src',
47
+ port: 5121,
48
+ }
53
49
  },
54
50
  },
55
51
  })
package/dist/index.d.mts CHANGED
@@ -12,9 +12,12 @@ interface Global {
12
12
  declare class UniAppEnvironment implements Environment {
13
13
  name: string;
14
14
  viteEnvironment: string;
15
+ private TIME_TEARDOWN;
15
16
  private _store;
16
- setup(global: Global, options: UniInitOptions): Promise<{
17
- teardown(global: Global): Promise<void>;
17
+ setup(global: Global, options: {
18
+ uniapp?: UniInitOptions;
19
+ }): Promise<{
20
+ teardown: (global: Global) => Promise<void>;
18
21
  }>;
19
22
  }
20
23
  declare const uniAppEnvironment: UniAppEnvironment;
package/dist/index.mjs CHANGED
@@ -6,32 +6,35 @@ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6
6
  var UniAppEnvironment = class {
7
7
  name = "uni-app";
8
8
  viteEnvironment = "ssr";
9
+ TIME_TEARDOWN = 3e3;
9
10
  _store = { init: false };
10
11
  async setup(global, options) {
12
+ const uniappOptions = options?.uniapp;
11
13
  if (this._store.init) {
12
14
  if (!global.program) throw new Error("测试环境初始化失败,请重新运行测试");
13
15
  } else try {
14
- this._store.init = true;
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;
25
+ this._store.init = true;
24
26
  } catch (error) {
27
+ this._store.init = false;
25
28
  console.error("测试环境初始化失败", error);
26
29
  throw error;
27
30
  }
28
31
  global.uni = this._store.uni;
29
32
  global.program = this._store.program;
30
- return { async teardown(global$1) {
33
+ return { teardown: async (global$1) => {
31
34
  const { program } = global$1;
32
35
  if (program && typeof program.teardown === "function") {
33
36
  await program.teardown();
34
- await sleep(3e3);
37
+ await sleep(this.TIME_TEARDOWN);
35
38
  }
36
39
  } };
37
40
  }
package/global.d.ts CHANGED
@@ -1,3 +1,39 @@
1
+ import 'vitest/node'
2
+
3
+ declare module 'vitest/node' {
4
+ interface EnvironmentOptions {
5
+ /**
6
+ * uniapp 测试环境选项,详情请参考[uni-app 自动化测试](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs)
7
+ */
8
+ uniapp?: {
9
+ /**
10
+ * H5 测试选项
11
+ */
12
+ 'h5': {
13
+ [x: string]: unknown
14
+ }
15
+ /**
16
+ * app-plus 测试选项, 需要安装 HBuilderX
17
+ */
18
+ 'app-plus': {
19
+ [x: string]: unknown
20
+ }
21
+ /**
22
+ * 微信小程序测试选项
23
+ */
24
+ 'mp-weixin': {
25
+ [x: string]: unknown
26
+ }
27
+ /**
28
+ * 支付宝小程序测试选项
29
+ */
30
+ 'mp-alipay': {
31
+ [x: string]: unknown
32
+ }
33
+ }
34
+ }
35
+ }
36
+
1
37
  declare global {
2
38
  /**
3
39
  * Element 模块提供了控制页面元素的方法
@@ -442,4 +478,5 @@ declare global {
442
478
  exposeFunction: (name: string, bindingFunction: (() => unknown)) => Promise<void>
443
479
  }
444
480
  }
481
+
445
482
  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.2",
4
+ "version": "0.0.4",
5
5
  "description": "Vitest environment for UniApp",
6
6
  "author": "FliPPeDround <flippedround@qq.com>",
7
7
  "license": "MIT",
@@ -29,14 +29,13 @@
29
29
  "global.d.ts"
30
30
  ],
31
31
  "peerDependencies": {
32
- "@dcloudio/uni-automator": "3.0.0-4080720251210001"
33
- },
34
- "dependencies": {
35
- "playwright": "^1.58.2"
32
+ "@dcloudio/uni-automator": "*",
33
+ "vitest": "*"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@antfu/eslint-config": "^6.6.1",
39
37
  "@antfu/ni": "^28.0.0",
38
+ "@dcloudio/uni-automator": "3.0.0-4080720251210001",
40
39
  "@types/node": "^25.0.1",
41
40
  "bumpp": "^10.3.2",
42
41
  "eslint": "^9.39.2",