also looking at this
test(sdk): eliminate retained-window fixture collisions
#302
3 files
+17
-5
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -97,6 +97,9 @@ jobs: | ||
| 97 | 97 | working-directory: packages/typescript |
| 98 | 98 | run: bun test --coverage |
| 99 | 99 | |
| 100 | - name: Soak retained window routing across fresh DOM fixtures | |
| 101 | run: bun run test:window-routing | |
| 102 | ||
| 100 | 103 | - name: Generate coverage summary |
| 101 | 104 | if: always() |
| 102 | 105 | working-directory: packages/typescript |
| @@ -37,6 +37,7 @@ | ||
| 37 | 37 | "verify:docs": "bun scripts/verify-doc-links.ts", |
| 38 | 38 | "test": "command -v zig >/dev/null 2>&1 || eval \"$(pantry env | sed -n '/^export /,$p')\"; cd packages/zig && zig build test", |
| 39 | 39 | "test:sdk": "cd packages/typescript && bun test", |
| 40 | "test:window-routing": "bun test packages/typescript/src/__tests__/window-routing.test.ts --rerun-each=100 --randomize --seed=254", | |
| 40 | 41 | "test:native-lifecycle": "bun scripts/native-lifecycle.ts", |
| 41 | 42 | "test:mobile-e2e:ios": "bun scripts/mobile-e2e.ts --platform ios --ios-runtime packages/zig/zig-out/lib", |
| 42 | 43 | "test:mobile-e2e:android": "bun scripts/mobile-e2e.ts --platform android --android-runtime packages/zig/zig-out/android", |
| @@ -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 | // The manager retains stable handles across fixtures and Bun reruns. Wall | |
| 15 | // clock milliseconds can collide while each test installs a fresh fake DOM. | |
| 16 | let clock: ReturnType<typeof spyOn> | |
| 17 | const fixtureId = (label: string) => `${label}-${randomUUID()}` | |
| 13 | 18 | |
| 14 | 19 | beforeEach(() => { |
| 20 | // Keep time fixed so reintroducing Date.now() IDs fails deterministically. | |
| 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) |