constants.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * 默认超时配置(毫秒)
  3. *
  4. * @description
  5. * 定义各种操作的默认超时时间。所有工具函数都应该使用这些常量而不是硬编码超时值。
  6. *
  7. * @example
  8. * ```ts
  9. * const timeout = options.timeout ?? DEFAULT_TIMEOUTS.static;
  10. * ```
  11. */
  12. export const DEFAULT_TIMEOUTS = {
  13. /** 静态选项超时(5秒)- 增加以适应不同环境*/
  14. static: 5000,
  15. /** 异步选项超时(10秒)- 增加以适应网络慢的环境*/
  16. async: 10000,
  17. /** 网络空闲超时(15秒)- 增加以适应网络慢的环境*/
  18. networkIdle: 15000
  19. } as const;
  20. /**
  21. * 选择器策略常量
  22. *
  23. * @description
  24. * 定义选择器查找的优先级顺序,用于应对 Radix UI 版本升级。
  25. *
  26. * 优先级顺序:
  27. * 1. `data-testid` - 最稳定,推荐用于测试
  28. * 2. `aria-label + role` - 无障碍属性,较为稳定
  29. * 3. `text content + role` - 文本内容,最不稳定但最通用
  30. *
  31. * @example
  32. * ```ts
  33. * // 按优先级尝试选择器
  34. * for (const strategy of SELECTOR_STRATEGIES) {
  35. * const element = await findByStrategy(strategy, label);
  36. * if (element) return element;
  37. * }
  38. * ```
  39. */
  40. export const SELECTOR_STRATEGIES = [
  41. 'data-testid',
  42. 'aria-label + role',
  43. 'text content + role'
  44. ] as const;
  45. /**
  46. * 选择器策略类型
  47. *
  48. * @description
  49. * 选择器策略的联合类型,用于类型检查。
  50. *
  51. * @example
  52. * ```ts
  53. * function findByStrategy(strategy: SelectorStrategy, label: string) {
  54. * // ...
  55. * }
  56. * ```
  57. */
  58. export type SelectorStrategy = typeof SELECTOR_STRATEGIES[number];