Skip to content

Conversation

@sambostock
Copy link
Contributor

Being passed { port: '0' } ({ port: string }) is a Typescript type error, but we explicitly have a test that checks that it is gracefully handled, with behavior matching being passed

  • { port: 0 } ({ port: number }),
  • '0' (string), or
  • 0 (number),

which all convert the port to 0.

However, that test was actually dependent on the following leak from a test above it:

process.env.HOST = 'localhost';

Switching to vi.stubEnv and ensuring to call vi.unstubAllEnvs reveals that the behavior is broken.


This updates the behavior to apply the same check to _userOptions.port as we do to _userOptions, and coerce number and string values to integers.

sambostock and others added 3 commits November 27, 2024 00:08
Being passed `{ port: '0' }` (`{ port: string }`) is a Typescript type
error, but we explicitly have a test that checks that it is gracefully
handled, with behavior matching being passed

- `{ port: 0 }` (`{ port: number }`),
- `'0'` (`string`), or
- `0` (`number`),

which all convert the `port` to `0`.

However, that test was actually dependent on the following leak from a
test above it:

    process.env.HOST = 'localhost';

Switching to `vi.stubEnv` and ensuring to call `vi.unstubAllEnvs`
reveals that the behavior is broken.

This updates the behavior to apply the same check to `_userOptions.port`
as we do to `_userOptions`, and coerce `number` and `string` values to
integers.
@pi0 pi0 changed the title Fix handling of { port: '0' } fix: handle { port: "0" } Feb 7, 2025

describe("localhost", () => {
afterEach(() => {
vi.unstubAllEnvs();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems sonehow breaking tests os.networkInterfaces() becomes undefined

typeof _userOptions.port === "number" ||
typeof _userOptions.port === "string" // Shouldn't happen, but just in case
) {
_userOptions.port = Number.parseInt(_userOptions.port + "") || 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be silent ~> random behavior if port is XYZ it will become 0 silently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants