Summary
ScriptImporter is a core debugger component with no dedicated unit tests. It contains pure URL construction and manipulation methods that have version-dependent branching, making them good targets for focused unit tests.
Why this is useful
The prepareDebuggerWorkerURL and overridePackagerPort methods drive how the debugger connects to Metro. A bug in URL construction (wrong port, missing debugger-ui/ path for RN ≥ 0.50, wrong path for custom debuggerWorkerUrlPath) silently breaks debugging sessions. Unit tests would catch regressions here without requiring a full integration run.
Suggested scope
- Add
test/debugger/scriptImporter.test.ts
- Test
prepareDebuggerWorkerURL for RN < 0.50, RN ≥ 0.50, canary versions, and explicit debuggerWorkerUrlPath override
- Test
overridePackagerPort with localhost URLs to verify port replacement without breaking query strings
- No need to test async I/O methods (
downloadAppScript, downloadDebuggerWorker) in this issue
Evidence
Validation
npm test passes with new test cases
- Test covers all three branches of
prepareDebuggerWorkerURL
Summary
ScriptImporteris a core debugger component with no dedicated unit tests. It contains pure URL construction and manipulation methods that have version-dependent branching, making them good targets for focused unit tests.Why this is useful
The
prepareDebuggerWorkerURLandoverridePackagerPortmethods drive how the debugger connects to Metro. A bug in URL construction (wrong port, missingdebugger-ui/path for RN ≥ 0.50, wrong path for custom debuggerWorkerUrlPath) silently breaks debugging sessions. Unit tests would catch regressions here without requiring a full integration run.Suggested scope
test/debugger/scriptImporter.test.tsprepareDebuggerWorkerURLfor RN < 0.50, RN ≥ 0.50, canary versions, and explicitdebuggerWorkerUrlPathoverrideoverridePackagerPortwith localhost URLs to verify port replacement without breaking query stringsdownloadAppScript,downloadDebuggerWorker) in this issueEvidence
src/debugger/scriptImporter.ts(206 lines) — no corresponding test file existsprepareDebuggerWorkerURLhas three branching paths based onsemver.gte(rnVersion, "0.50.0"),isCanaryVersion, anddebuggerWorkerUrlPath !== undefinedoverridePackagerPortdeletes thehostcomponent specifically to force port override — a subtle invariant with no test coverageValidation
npm testpasses with new test casesprepareDebuggerWorkerURL