File size: 868 Bytes
94193b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { describe, it, expect, beforeEach } from 'vitest';
import { markSessionStartedOnce, __resetSessionGuardForTests } from '../session-guard';
describe('markSessionStartedOnce', () => {
beforeEach(() => __resetSessionGuardForTests());
it('returns true only on the first call and false thereafter', () => {
expect(markSessionStartedOnce()).toBe(true);
expect(markSessionStartedOnce()).toBe(false);
expect(markSessionStartedOnce()).toBe(false);
});
it('models exactly one session_start across many bootstrap remounts', () => {
// Each server-mode route navigation remounts the bootstrap and calls the
// guard; the session must be counted once, not once per navigation.
let sessionStarts = 0;
for (let i = 0; i < 5; i++) {
if (markSessionStartedOnce()) sessionStarts++;
}
expect(sessionStarts).toBe(1);
});
});
|