| @@ -1,4 +1,5 @@ |
| 1 | | -import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test' |
| 1 | +import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test' |
| 2 | +import { randomUUID } from 'node:crypto' |
| 2 | 3 | import { Window, windowManager } from '../api/window' |
| 3 | 4 | |
| 4 | 5 | describe('typed window-handle routing', () => { |
| @@ -10,8 +11,14 @@ describe('typed window-handle routing', () => { |
| 10 | 11 | }) |
| 11 | 12 | const open = mock(async (options: { id: string }) => ({ name: options.id })) |
| 12 | 13 | const listeners = new Map<string, Set<EventListener>>() |
| 14 | + |
| 15 | + |
| 16 | + let clock: ReturnType<typeof spyOn> |
| 17 | + const fixtureId = (label: string) => `${label}-${randomUUID()}` |
| 13 | 18 | |
| 14 | 19 | beforeEach(() => { |
| 20 | + |
| 21 | + clock = spyOn(Date, 'now').mockReturnValue(0) |
| 15 | 22 | call.mockClear() |
| 16 | 23 | callResult = undefined |
| 17 | 24 | open.mockClear() |
| @@ -34,6 +41,7 @@ describe('typed window-handle routing', () => { |
| 34 | 41 | }) |
| 35 | 42 | |
| 36 | 43 | afterEach(() => { |
| 44 | + clock.mockRestore() |
| 37 | 45 | if (previousWindow === undefined) { |
| 38 | 46 | Reflect.deleteProperty(globalThis, 'window') |
| 39 | 47 | } |
| @@ -113,7 +121,7 @@ describe('typed window-handle routing', () => { |
| 113 | 121 | }) |
| 114 | 122 | |
| 115 | 123 | it('revives the stable SDK handle around a fresh native window after destroy', async () => { |
| 116 | | - const id = `destroyed-${Date.now()}` |
| 124 | + const id = fixtureId('destroyed') |
| 117 | 125 | const first = await windowManager.create({ id, html: '<h1>First</h1>' }) |
| 118 | 126 | await first.destroy() |
| 119 | 127 | |
| @@ -125,7 +133,7 @@ describe('typed window-handle routing', () => { |
| 125 | 133 | }) |
| 126 | 134 | |
| 127 | 135 | it('creates through the injected bridge instead of the incompatible generic envelope', async () => { |
| 128 | | - const id = `settings-${Date.now()}` |
| 136 | + const id = fixtureId('settings') |
| 129 | 137 | const created = await windowManager.create({ id, html: '<h1>Settings</h1>' }) |
| 130 | 138 | |
| 131 | 139 | expect(open).toHaveBeenCalledWith({ id, html: '<h1>Settings</h1>' }) |
| @@ -139,7 +147,7 @@ describe('typed window-handle routing', () => { |
| 139 | 147 | }) |
| 140 | 148 | |
| 141 | 149 | it('resolves the focused retained handle through the injected bridge', async () => { |
| 142 | | - const id = `focused-${Date.now()}` |
| 150 | + const id = fixtureId('focused') |
| 143 | 151 | const settings = await windowManager.create({ id, html: '<h1>Settings</h1>' }) |
| 144 | 152 | callResult = id |
| 145 | 153 | |
| @@ -148,7 +156,7 @@ describe('typed window-handle routing', () => { |
| 148 | 156 | }) |
| 149 | 157 | |
| 150 | 158 | it('revives the same handle and its listeners when a named window is reopened', async () => { |
| 151 | | - const id = `reopened-${Date.now()}` |
| 159 | + const id = fixtureId('reopened') |
| 152 | 160 | const settings = await windowManager.create({ id, html: '<h1>Settings</h1>' }) |
| 153 | 161 | const onResize = mock(() => {}) |
| 154 | 162 | settings.on('resize', onResize) |