@be-link/smart-test 1.0.1-beta.10 → 1.0.1-beta.12

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.
Files changed (53) hide show
  1. package/README.md +25 -63
  2. package/dist/bin/smart-test.d.ts +2 -0
  3. package/dist/bin/smart-test.d.ts.map +1 -0
  4. package/dist/bin/smart-test.js +21669 -0
  5. package/dist/cli/commands/gen.d.ts +2 -0
  6. package/dist/cli/commands/gen.d.ts.map +1 -0
  7. package/dist/cli/commands/generate-mock.d.ts +6 -0
  8. package/dist/cli/commands/generate-mock.d.ts.map +1 -0
  9. package/dist/cli/commands/generate-testcase.d.ts +6 -0
  10. package/dist/cli/commands/generate-testcase.d.ts.map +1 -0
  11. package/dist/cli/commands/index.d.ts +2 -0
  12. package/dist/cli/commands/index.d.ts.map +1 -0
  13. package/dist/cli/commands/init.d.ts +7 -0
  14. package/dist/cli/commands/init.d.ts.map +1 -0
  15. package/dist/cli/core/config-loader.d.ts +69 -0
  16. package/dist/cli/core/config-loader.d.ts.map +1 -0
  17. package/dist/cli/core/env-loader.d.ts +6 -0
  18. package/dist/cli/core/env-loader.d.ts.map +1 -0
  19. package/dist/cli/core/validators.d.ts +27 -0
  20. package/dist/cli/core/validators.d.ts.map +1 -0
  21. package/dist/cli/templates/playwright.config.template.d.ts +7 -0
  22. package/dist/cli/templates/playwright.config.template.d.ts.map +1 -0
  23. package/dist/cli/templates/playwright.config.template.ts +47 -0
  24. package/dist/cli/templates/smart-test.config.template.json +17 -0
  25. package/dist/cli/ui/interactive.d.ts +29 -0
  26. package/dist/cli/ui/interactive.d.ts.map +1 -0
  27. package/dist/core/ai-assistant.d.ts +1 -46
  28. package/dist/core/ai-assistant.d.ts.map +1 -1
  29. package/dist/core/config.d.ts +10 -36
  30. package/dist/core/config.d.ts.map +1 -1
  31. package/dist/core/prompts.d.ts +3 -3
  32. package/dist/core/prompts.d.ts.map +1 -1
  33. package/dist/core/types.d.ts +126 -94
  34. package/dist/core/types.d.ts.map +1 -1
  35. package/dist/generators/index.d.ts +4 -0
  36. package/dist/generators/index.d.ts.map +1 -0
  37. package/dist/generators/mock-generator.d.ts +6 -0
  38. package/dist/generators/mock-generator.d.ts.map +1 -0
  39. package/dist/generators/testcase-generator.d.ts +6 -0
  40. package/dist/generators/testcase-generator.d.ts.map +1 -0
  41. package/dist/index.d.ts +4 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.esm.mjs +21260 -0
  44. package/dist/index.js +20987 -115
  45. package/dist/utils/file-writer.d.ts +13 -0
  46. package/dist/utils/file-writer.d.ts.map +1 -0
  47. package/dist/utils/type-extractor.d.ts +10 -0
  48. package/dist/utils/type-extractor.d.ts.map +1 -0
  49. package/package.json +8 -6
  50. package/dist/cli.d.ts +0 -2
  51. package/dist/cli.d.ts.map +0 -1
  52. package/dist/cli.js +0 -379
  53. package/dist/index.esm.js +0 -405
package/README.md CHANGED
@@ -17,19 +17,33 @@ pnpm add -D @be-link/smart-test
17
17
 
18
18
  ## 🚀 快速开始
19
19
 
20
- ### 1. 配置 AI API
20
+ ### 1. 初始化配置
21
21
 
22
- ```typescript
23
- import { configure } from '@be-link/smart-test';
22
+ 首先在项目中初始化配置文件:
24
23
 
25
- configure({
26
- apiKey: process.env.AI_API_KEY,
27
- baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
28
- visionModel: 'qwen3-vl-plus',
29
- codeModel: 'qwen3-coder-plus',
30
- });
24
+ ```bash
25
+ # 在项目根目录运行
26
+ smart-test init
27
+ ```
28
+
29
+ 然后编辑 `tests/smart-test.config.cjs`,配置 AI API 密钥:
30
+
31
+ ```javascript
32
+ module.exports = {
33
+ ai: {
34
+ apiKey: process.env.VITE_AI_API_KEY || '',
35
+ baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1',
36
+ visionModel: 'qwen3-vl-plus',
37
+ codeModel: 'qwen3-coder-plus',
38
+ },
39
+ // ... 其他配置
40
+ };
31
41
  ```
32
42
 
43
+ > **注意**:配置文件使用 `.cjs` 扩展名,确保在 ESM 项目(`"type": "module"`)中也能正常使用。
44
+
45
+ 配置文件会在使用 AI 功能时自动加载,无需手动调用配置函数。
46
+
33
47
  ### 2. AI 视觉检查
34
48
 
35
49
  在 Playwright 测试中使用 AI 检查页面截图:
@@ -286,22 +300,6 @@ interface AiCodeGenerationResult {
286
300
  }
287
301
  ```
288
302
 
289
- ### configure
290
-
291
- 配置全局 AI 设置。
292
-
293
- ```typescript
294
- function configure(config: Partial<AiBaseConfig>): void;
295
-
296
- interface AiBaseConfig {
297
- apiKey?: string; // AI API 密钥
298
- baseURL?: string; // AI 服务地址
299
- visionModel?: string; // 视觉模型名称
300
- codeModel?: string; // 代码模型名称
301
- timeout?: number; // 请求超时时间(毫秒)
302
- }
303
- ```
304
-
305
303
  ## 🎯 使用场景
306
304
 
307
305
  ### 场景 1:视觉回归测试
@@ -387,45 +385,9 @@ const result = await aiGenerateMock({
387
385
  }
388
386
  ```
389
387
 
390
- ### 自定义配置
391
-
392
- 可以在全局配置中设置默认值,也可以在每次调用时覆盖:
393
-
394
- ```typescript
395
- // 全局配置
396
- configure({
397
- apiKey: process.env.AI_API_KEY,
398
- visionModel: 'custom-vision-model',
399
- });
400
-
401
- // 单次调用覆盖
402
- await aiReviewScreenshot(page, {
403
- expected: '...',
404
- visionModel: 'another-model', // 仅此次调用使用
405
- });
406
- ```
407
-
408
388
  ## 🔍 最佳实践
409
389
 
410
- ### 1. 环境变量管理
411
-
412
- 建议将 API Key 存储在环境变量中:
413
-
414
- ```typescript
415
- // playwright.config.ts
416
- import { defineConfig } from '@playwright/test';
417
- import { configure } from '@be-link/smart-test';
418
-
419
- configure({
420
- apiKey: process.env.AI_API_KEY,
421
- });
422
-
423
- export default defineConfig({
424
- // ... 其他配置
425
- });
426
- ```
427
-
428
- ### 2. 合理使用 AI 检查
390
+ ### 1. 合理使用 AI 检查
429
391
 
430
392
  AI 视觉检查适合用于:
431
393
 
@@ -439,7 +401,7 @@ AI 视觉检查适合用于:
439
401
  - ❌ 颜色值精确匹配
440
402
  - ❌ 性能敏感的场景
441
403
 
442
- ### 3. 组合使用
404
+ ### 2. 组合使用
443
405
 
444
406
  将 AI 检查与传统断言结合使用,获得最佳效果:
445
407
 
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=smart-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smart-test.d.ts","sourceRoot":"","sources":["../../src/bin/smart-test.ts"],"names":[],"mappings":""}