ReviewOS

also looking at this

craft-native/craft

test(sdk): eliminate retained-window fixture collisions

#302
Merged glennmichael123 wants to merge codex/window-routing-test-isolation into main
3 files +17 -5
.github/workflows/ci.ymlmodified+3-0
Changes to .github/workflows/ci.yml
@@ -97,6 +97,9 @@ jobs:
9797 working-directory: packages/typescript
9898 run: bun test --coverage
9999
100 - name: Soak retained window routing across fresh DOM fixtures
101 run: bun run test:window-routing
102
100103 - name: Generate coverage summary
101104 if: always()
102105 working-directory: packages/typescript
package.jsonmodified+1-0
Changes to package.json
@@ -37,6 +37,7 @@
3737 "verify:docs": "bun scripts/verify-doc-links.ts",
3838 "test": "command -v zig >/dev/null 2>&1 || eval \"$(pantry env | sed -n '/^export /,$p')\"; cd packages/zig && zig build test",
3939 "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",
4041 "test:native-lifecycle": "bun scripts/native-lifecycle.ts",
4142 "test:mobile-e2e:ios": "bun scripts/mobile-e2e.ts --platform ios --ios-runtime packages/zig/zig-out/lib",
4243 "test:mobile-e2e:android": "bun scripts/mobile-e2e.ts --platform android --android-runtime packages/zig/zig-out/android",
packages/typescript/src/__tests__/window-routing.test.tsmodified+13-5
Changes to packages/typescript/src/__tests__/window-routing.test.ts
@@ -1,4 +1,5 @@
1import { afterEach, beforeEach, describe, expect, it, mock } from 'bun:test'
1import { afterEach, beforeEach, describe, expect, it, mock, spyOn } from 'bun:test'
2import { randomUUID } from 'node:crypto'
23import { Window, windowManager } from '../api/window'
34
45describe('typed window-handle routing', () => {
@@ -10,8 +11,14 @@ describe('typed window-handle routing', () => {
1011 })
1112 const open = mock(async (options: { id: string }) => ({ name: options.id }))
1213 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()}`
1318
1419 beforeEach(() => {
20 // Keep time fixed so reintroducing Date.now() IDs fails deterministically.
21 clock = spyOn(Date, 'now').mockReturnValue(0)
1522 call.mockClear()
1623 callResult = undefined
1724 open.mockClear()
@@ -34,6 +41,7 @@ describe('typed window-handle routing', () => {
3441 })
3542
3643 afterEach(() => {
44 clock.mockRestore()
3745 if (previousWindow === undefined) {
3846 Reflect.deleteProperty(globalThis, 'window')
3947 }
@@ -113,7 +121,7 @@ describe('typed window-handle routing', () => {
113121 })
114122
115123 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')
117125 const first = await windowManager.create({ id, html: '<h1>First</h1>' })
118126 await first.destroy()
119127
@@ -125,7 +133,7 @@ describe('typed window-handle routing', () => {
125133 })
126134
127135 it('creates through the injected bridge instead of the incompatible generic envelope', async () => {
128 const id = `settings-${Date.now()}`
136 const id = fixtureId('settings')
129137 const created = await windowManager.create({ id, html: '<h1>Settings</h1>' })
130138
131139 expect(open).toHaveBeenCalledWith({ id, html: '<h1>Settings</h1>' })
@@ -139,7 +147,7 @@ describe('typed window-handle routing', () => {
139147 })
140148
141149 it('resolves the focused retained handle through the injected bridge', async () => {
142 const id = `focused-${Date.now()}`
150 const id = fixtureId('focused')
143151 const settings = await windowManager.create({ id, html: '<h1>Settings</h1>' })
144152 callResult = id
145153
@@ -148,7 +156,7 @@ describe('typed window-handle routing', () => {
148156 })
149157
150158 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')
152160 const settings = await windowManager.create({ id, html: '<h1>Settings</h1>' })
153161 const onResize = mock(() => {})
154162 settings.on('resize', onResize)