vitest-environment-uniapp 0.0.1 → 0.0.3

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
@@ -1,11 +1,16 @@
1
1
  <a href="https://uni-helper.js.org/vitest-environment-uniapp"><img src="./banner.svg" alt="banner" width="100%"/></a>
2
2
 
3
3
  <a href="https://github.com/uni-helper/vitest-environment-uniapp/stargazers"><img src="https://img.shields.io/github/stars/uni-helper/vitest-environment-uniapp?colorA=005947&colorB=eee&style=for-the-badge"></a>
4
- <a href="https://www.npmjs.com/package/flippedround/vitest-environment-uniapp"><img src="https://img.shields.io/npm/dm/flippedround/vitest-environment-uniapp?colorA=005947&colorB=eee&style=for-the-badge"></a>
5
- <a href="https://www.npmjs.com/package/flippedround/vitest-environment-uniapp"><img src="https://img.shields.io/npm/v/flippedround/vitest-environment-uniapp?colorA=005947&colorB=eee&style=for-the-badge"></a>
4
+ <a href="https://www.npmjs.com/package/flippedround/vitest-environment-uniapp"><img src="https://img.shields.io/npm/dm/vitest-environment-uniapp?colorA=005947&colorB=eee&style=for-the-badge"></a>
5
+ <a href="https://www.npmjs.com/package/flippedround/vitest-environment-uniapp"><img src="https://img.shields.io/npm/v/vitest-environment-uniapp?colorA=005947&colorB=eee&style=for-the-badge"></a>
6
6
  <br/>
7
7
 
8
- # [uni-helper](https://uni-helper.js.org) 封装的uni命令
8
+ # Vitest uni-app e2e 测试环境
9
+
10
+ > [!IMPORTANT]
11
+ > 该项目依赖 `@dcloudio/uni-automator` 必须安装
12
+ > h5 平台下,需要安装 `playwright` ; 但目前无法获取启动状态导致超时
13
+ > environmentOptions 参数同 [uni-app 官方文档](https://uniapp.dcloud.net.cn/worktile/auto/quick-start.html#jestconfigjs) , 但官网长久未更新,导致参数与实际不符
9
14
 
10
15
  ## 安装
11
16
 
@@ -15,22 +20,20 @@ pnpm i -D vitest-environment-uniapp
15
20
 
16
21
  ## 使用
17
22
 
18
-
19
23
  ```bash
20
24
  pnpm test
21
25
  ```
22
-
26
+ > package.json
23
27
  ```json
24
- // package.json
25
28
  {
26
29
  "scripts": {
27
- "test": "vitest",
30
+ "test": "vitest"
28
31
  }
29
32
  }
30
33
  ```
31
34
 
35
+ > vitest.config.ts
32
36
  ```ts
33
- // unh.config.ts
34
37
  import { defineConfig } from 'vitest/config'
35
38
 
36
39
  export default defineConfig({
@@ -50,5 +53,14 @@ export default defineConfig({
50
53
  },
51
54
  },
52
55
  })
53
-
56
+ ```
57
+ > tsconfig.json
58
+ ```json
59
+ {
60
+ "compilerOptions": {
61
+ "types": [
62
+ "vitest-environment-uniapp/types"
63
+ ]
64
+ }
65
+ }
54
66
  ```
package/dist/index.d.mts CHANGED
@@ -6,16 +6,16 @@ import { Environment } from "vitest/environments";
6
6
  interface Global {
7
7
  program: {
8
8
  teardown: () => Promise<void>;
9
- remote: (enable: boolean) => Promise<void>;
10
9
  };
11
10
  uni: unknown;
12
11
  }
13
12
  declare class UniAppEnvironment implements Environment {
14
13
  name: string;
15
14
  viteEnvironment: string;
15
+ private TIME_TEARDOWN;
16
16
  private _store;
17
17
  setup(global: Global, options: UniInitOptions): Promise<{
18
- teardown(global: Global): Promise<void>;
18
+ teardown: (global: Global) => Promise<void>;
19
19
  }>;
20
20
  }
21
21
  declare const uniAppEnvironment: UniAppEnvironment;
package/dist/index.mjs CHANGED
@@ -6,32 +6,34 @@ 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) {
11
12
  if (this._store.init) {
12
13
  if (!global.program) throw new Error("测试环境初始化失败,请重新运行测试");
13
14
  } else try {
14
- this._store.init = true;
15
15
  const platform = options?.platform || process.env.UNI_PLATFORM;
16
16
  const program = await new Automator().launch({
17
17
  ...options,
18
18
  platform
19
19
  });
20
- if (options?.devtools?.remote) await global.program.remote(true);
20
+ if (options?.devtools?.remote) await program.remote(true);
21
21
  const uni = initUni(program);
22
22
  this._store.uni = uni;
23
23
  this._store.program = program;
24
+ this._store.init = true;
24
25
  } catch (error) {
26
+ this._store.init = false;
25
27
  console.error("测试环境初始化失败", error);
26
28
  throw error;
27
29
  }
28
30
  global.uni = this._store.uni;
29
31
  global.program = this._store.program;
30
- return { async teardown(global$1) {
32
+ return { teardown: async (global$1) => {
31
33
  const { program } = global$1;
32
34
  if (program && typeof program.teardown === "function") {
33
35
  await program.teardown();
34
- await sleep(3e3);
36
+ await sleep(this.TIME_TEARDOWN);
35
37
  }
36
38
  } };
37
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vitest-environment-uniapp",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "description": "Vitest environment for UniApp",
6
6
  "author": "FliPPeDround <flippedround@qq.com>",
7
7
  "license": "MIT",
@@ -28,15 +28,10 @@
28
28
  "dist",
29
29
  "global.d.ts"
30
30
  ],
31
- "peerDependencies": {
32
- "@dcloudio/uni-automator": "3.0.0-4080720251210001"
33
- },
34
- "dependencies": {
35
- "playwright": "^1.58.2"
36
- },
37
31
  "devDependencies": {
38
32
  "@antfu/eslint-config": "^6.6.1",
39
33
  "@antfu/ni": "^28.0.0",
34
+ "@dcloudio/uni-automator": "3.0.0-4080720251210001",
40
35
  "@types/node": "^25.0.1",
41
36
  "bumpp": "^10.3.2",
42
37
  "eslint": "^9.39.2",