What happens in tests when the requested port is in use? What's verified?
What happens in tests when the requested port is in use? What's verified?
About sindresorhus/get-port · 2 messages · last activity 6/8/2026
I don't have visibility into the test files in the indexed repository. The thin index coverage (8 of 8 eligible files) doesn't include test code that would show what's verified when a requested port is in use.
However, based on the README excerpt provided, here's what the library's behavior should be when a requested port is unavailable:
- If you pass a single preferred port (e.g.,
port: 3000), the library "will use 3000 if available, otherwise fall back to a random port" - If you pass an array of preferred ports (e.g.,
port: [3000, 3001, 3002]), it "will use any element in the preferred ports array if available, otherwise fall back to a random port" - You can also use the
excludeoption to skip certain ports
To see what the actual tests verify, you'd need to examine the test files directly (likely in a test/ or spec/ directory). The most plausible entry point would be the main implementation file, which you can read to understand the fallback logic.
FOLLOW_UPS:
- How does the library detect port availability?
- What does the
reserveoption do exactly? - How does
portNumbers()helper function work?
Want to ask your own question?
Open chat for sindresorhus/get-port →Public Q&A. Generated by RepoPilot from the actual source of sindresorhus/get-port. AI answers can be incomplete or stale — verify before relying on them.