MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / createShouldShowReportDialog

Function createShouldShowReportDialog

tests/modules/sentry-feedback.test.js:82–131  ·  view source on GitHub ↗

* 独立实现 shouldShowReportDialog,与 sentry-loader.js 逻辑一致 * 用于单元测试冷却机制的正确性

(options = {})

Source from the content-addressed store, hash-verified

80 * 用于单元测试冷却机制的正确性
81 */
82function createShouldShowReportDialog(options = {}) {
83 const { isDev = false } = options;
84 let lastReportDialogTime = 0;
85 let lastReportDialogFingerprint = '';
86 const COOLDOWN_MS = 60000;
87
88 function shouldShowReportDialog(event) {
89 const empty = { shouldShow: false, fingerprint: '' };
90
91 // 空事件防御
92 if (!event || typeof event !== 'object') return empty;
93
94 // 仅生产环境弹窗
95 if (isDev) return empty;
96
97 // 仅对异常事件弹窗(captureMessage 等不弹)
98 if (!event.exception || !event.exception.values || !event.exception.values.length) {
99 return empty;
100 }
101
102 // 生成错误指纹:取第一个异常的 type + value 组合
103 const firstException = event.exception.values[0];
104 const fingerprint = (firstException.type || '') + ':' + (firstException.value || '');
105
106 // 冷却检查:避免短时间内反复弹窗
107 const now = Date.now();
108 if (now - lastReportDialogTime < COOLDOWN_MS) {
109 return { shouldShow: false, fingerprint };
110 }
111
112 // 同一错误不重复弹窗
113 if (fingerprint === lastReportDialogFingerprint) {
114 return { shouldShow: false, fingerprint };
115 }
116
117 return { shouldShow: true, fingerprint };
118 }
119
120 function reset() {
121 lastReportDialogTime = 0;
122 lastReportDialogFingerprint = '';
123 }
124
125 function simulateDialogShown(fingerprint) {
126 lastReportDialogTime = Date.now();
127 lastReportDialogFingerprint = fingerprint;
128 }
129
130 return { shouldShowReportDialog, reset, simulateDialogShown };
131}
132
133// ===================================
134// 测试用例

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected