refactor(test): improve type safety for spawned process URLs#7219
refactor(test): improve type safety for spawned process URLs#7219
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7219 +/- ##
=======================================
Coverage 84.56% 84.56%
=======================================
Files 532 532
Lines 22656 22656
=======================================
Hits 19159 19159
Misses 3497 3497 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Overall package sizeSelf size: 4.39 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.0 | 68.46 kB | 797.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
This comment has been minimized.
This comment has been minimized.
BenchmarksBenchmark execution time: 2026-01-14 13:44:54 Comparing candidate commit 47e45ba in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 289 metrics, 31 unstable metrics. |
3a0da08 to
09f5e10
Compare
2fe3616 to
02625e4
Compare
- Split `spawnProc` into two functions with distinct return types: - `spawnProc`: expects long-running processes, always returns SpawnedProcess with `url` - `spawnProcAndExpectExit`: expects clean exit, may return void - Make `url` property a lazy getter that throws if accessed before port message - Ensures TypeScript knows `proc.url` is always defined for long-running processes - Update startup test to use `spawnProcAndExpectExit` for short-lived process
02625e4 to
dbfb772
Compare
BridgeAR
left a comment
There was a problem hiding this comment.
LGTM, as it already improves things further. I believe overload should just be added to all cases to remove even more type error reports.
- Split `spawnProc` into two functions with distinct return types: - `spawnProc`: expects long-running processes, always returns SpawnedProcess with `url` - `spawnProcAndExpectExit`: expects clean exit, may return void - Make `url` property a lazy getter that throws if accessed before port message - Ensures TypeScript knows `proc.url` is always defined for long-running processes
- Split `spawnProc` into two functions with distinct return types: - `spawnProc`: expects long-running processes, always returns SpawnedProcess with `url` - `spawnProcAndExpectExit`: expects clean exit, may return void - Make `url` property a lazy getter that throws if accessed before port message - Ensures TypeScript knows `proc.url` is always defined for long-running processes

What does this PR do?
Refactors the
spawnProctest helper to improve TypeScript type safety by splitting it into two distinct functions with clear lifecycle expectations and return types.Motivation
When using
spawnProc, TypeScript would complain thatproc.urlmight be undefined, even in cases where we know the process is long-running and will definitely send a port message. This was because the function could return eitherSpawnedProcess(withurl) orvoiddepending on whether the process exited or stayed alive.This refactoring:
spawnProcalways returnSpawnedProcesswith a guaranteedurlproperty (rejects if process exits)spawnProcAndExpectExitfor processes that should run and exit cleanly (returnsvoidon success)urlas a lazy getter that throws if accessed before the port message is received (prevents timing bugs)This ensures TypeScript correctly understands that
proc.urlis always defined when usingspawnProc, eliminating false-positive type errors.Additional Notes
This is purely a refactoring of test infrastructure with no impact on production code.
Changes to test helpers:
spawnPluginIntegrationTestProcAndExpectExitwrapper for short-lived plugin integration testsUpdated tests:
Updated various plugin integration tests and other test files to use the appropriate spawn function based on whether they spawn long-running servers (use
spawnProc/spawnPluginIntegrationTestProc) or short-lived scripts that run and exit (usespawnProcAndExpectExit/spawnPluginIntegrationTestProcAndExpectExit).