vitest-environment-uniapp 0.0.3 → 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
@@ -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
@@ -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,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.3",
4
+ "version": "0.0.4",
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",