Skip to content

Commit d800636

Browse files
fix(dotcom): suppress confusing KV error output in feature flags test (tldraw#8405)
The KV error fallback test in `featureFlags.test.ts` intentionally throws to verify graceful degradation, but the `console.error` from the catch block was showing up in CI output and looked like a real failure: ``` Failed to get feature flag zero_kill_switch: Error: KV down at Object.<anonymous> (.../featureFlags.test.ts:170:10) ``` This suppresses the expected `console.error` during the test. Example run [here](https://github.com/tldraw/tldraw/actions/runs/23846844691/job/69516189133?pr=8031#step:15:894). ### Change type - [x] `improvement` ### Test plan - [x] Unit tests ### Code changes | Section | LOC change | | ------- | ---------- | | Tests | +2 / -0 |
1 parent 16eb327 commit d800636

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

apps/dotcom/client/src/tla/utils/FeatureFlagPoller.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ describe('fetchFeatureFlags', () => {
115115
mockFetch.mockReset()
116116
// Module-level fetchFeatureFlags() fires on import. Use an unauthenticated
117117
// response so the promise cache is cleared and each test starts fresh.
118+
// Two responses needed: one for the module-level call, one for the explicit await
119+
// (the unauthenticated response clears the cache, so the second call refetches).
120+
mockFetchResponse(makeFlags(), false)
118121
mockFetchResponse(makeFlags(), false)
119122
const mod = await import('./FeatureFlagPoller')
120123
fetchFeatureFlags = mod.fetchFeatureFlags
@@ -152,17 +155,21 @@ describe('fetchFeatureFlags', () => {
152155
})
153156

154157
it('returns default flags on fetch error', async () => {
158+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
155159
mockFetch.mockRejectedValueOnce(new Error('network down'))
156160
const flags = await fetchFeatureFlags()
157161
expect(flags.zero_kill_switch.enabled).toBe(false)
158162
expect(flags.zero_enabled.enabled).toBe(false)
159163
expect(wasAuthenticated()).toBe(false)
164+
spy.mockRestore()
160165
})
161166

162167
it('returns default flags on non-ok response', async () => {
168+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
163169
mockFetch.mockResolvedValueOnce({ ok: false, status: 500 })
164170
const flags = await fetchFeatureFlags()
165171
expect(flags.zero_kill_switch.enabled).toBe(false)
166172
expect(flags.zero_enabled.enabled).toBe(false)
173+
spy.mockRestore()
167174
})
168175
})

apps/dotcom/sync-worker/src/utils/featureFlags.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,14 @@ describe('getFeatureFlagValue', () => {
165165
})
166166

167167
it('returns defaults on KV error', async () => {
168+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
168169
const env = makeEnv()
169170
env.FEATURE_FLAGS.get = vi.fn(async () => {
170171
throw new Error('KV down')
171172
})
172173
const value = await getFeatureFlagValue(env as any, 'zero_kill_switch')
173174
expect(value).toMatchObject({ type: 'boolean', enabled: false })
175+
consoleSpy.mockRestore()
174176
})
175177
})
176178

0 commit comments

Comments
 (0)