Repository navigation
useDeepLink のテストを flaky から安定化 - #6045
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesuseDeepLink テスト安定化
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
概要
src/hooks/useDeepLink.test.tsxが flaky だったので、テスト間のモック・タイマー漏れを断ち切り、実時間依存を fake timer 化して安定化させた。アプリ本体 (src/hooks/useDeepLink.ts等) の挙動には変更なし。変更の種類
変更内容
flaky の根本原因は次の 4 点だった:
jest.clearAllMocks()は.mock.callsのみクリアし、mockReturnValue/mockReturnValueOnceキューは保持される。navigationRef.isReadyの戻り値が前テストの設定を引き継いでいた。waitForNavReadyが仕込むsetTimeout(最大 1500ms) がテスト境界を越えて生き残り得た。for + Promise.resolve()ループが microtask の解決順に依存して脆かった。ナビゲーターがリトライ中に準備完了した場合はナビゲートするテストが実時間でwaitFor({ timeout: 5000 })していたため、CI 負荷で 100ms のsetTimeoutが遅延すると失敗し得た。対応:
beforeEachを追加し、Linking.*/navigationRef.*/resolveSidsFromShortIdのモックをmockReset()+ デフォルト再シードするafterEachにjest.clearAllTimers()+jest.useRealTimers()を追加し、fake timer 漏れに対する防御を入れるdescribe('id ...')/describe('tt* ...')内の重複したmockResolveSids.mockReset()afterEach を削除 (グローバル beforeEach で一括処理されるため)ナビゲーターが未準備の場合はリトライ後にナビゲートしないをjest.advanceTimersByTimeAsync(2000)で書き換え (手動 flushing を排除)ナビゲーターがリトライ中に準備完了した場合はナビゲートするを fake timer 化し、jest.advanceTimersByTimeAsync(200)で 100ms リトライを決定的に進める初回URL処理完了前はinitialUrlProcessedがfalseでrender()の戻り値のunmount()を呼び、永遠 pending なgetInitialURLPromise が次のテストへ漏れないようにするローカルで 10 連続実行・並列実行 (hooks 配下 56 ファイル 640 件) とも全件パスを確認した。
なお
Jest did not exit one second after the test run has completed警告は依然残るが、これは本テスト固有ではなくjest-expo/ Apollo Client の global teardown 起因と推測される。本 flaky の直接原因ではないため本 PR のスコープ外。テスト
npm run lintが通ることnpm testが通ることnpm run typecheckが通ること関連Issue
スクリーンショット(任意)
Summary by CodeRabbit
リリースノート