import { describe, it, beforeEach, afterEach } from 'node:test' import assert from 'node:assert/strict' import { register } from 'node:module' import { pathToFileURL } from 'node:url' // 隔离 refresh* 的 Pinia/HTTP/静态资源导入链,避免 node --import tsx --test 加载失败。 const stubUrl = 'data:text/javascript,' + [ 'export async function refreshOaMenuBadges() {}', 'export async function refreshQcMenuBadges() {}', 'export async function refreshProductionMenuBadges() {}' ].join('\n') const hookSource = ` const stubUrl = ${JSON.stringify(stubUrl)} const names = ['oa-menu-badge', 'qc-menu-badge', 'production-menu-badge'] export async function resolve(specifier, context, nextResolve) { const base = String(specifier).split('?')[0] if (names.some((name) => base === './' + name || base.endsWith('/' + name))) { return { shortCircuit: true, url: stubUrl } } return nextResolve(specifier, context) } ` register('data:text/javascript,' + encodeURIComponent(hookSource), pathToFileURL('./')) const { startMenuBadgePolling, stopMenuBadgePolling, isMenuBadgePollingActive, MENU_BADGE_POLL_INTERVAL_MS } = await import('./menu-badge-polling') describe('menu-badge-polling', () => { beforeEach(() => { stopMenuBadgePolling() }) afterEach(() => { stopMenuBadgePolling() }) it('exports 60s interval', () => { assert.equal(MENU_BADGE_POLL_INTERVAL_MS, 60_000) }) it('start is idempotent (single active flag)', () => { startMenuBadgePolling() startMenuBadgePolling() assert.equal(isMenuBadgePollingActive(), true) stopMenuBadgePolling() assert.equal(isMenuBadgePollingActive(), false) }) it('stop is safe when not started', () => { stopMenuBadgePolling() assert.equal(isMenuBadgePollingActive(), false) }) })