Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: probe types in test file #884

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fedealconada
Copy link
Contributor

@fedealconada fedealconada commented Nov 13, 2023

Fix Probe

I initially created the PR the fix the below bug but then I realised that there was something going on with this.

I discovered that ports are not supported by node-ping (see here) so I removed the ports test cases and also took advantage to refactor a bit the code PingMonitor.ts code as well as the tests.

NOTE: one could add support to ports probably by using other library or using sockets (and the net) but didn't add it here because it was a bit out of the scope.

Initial bug:

> [email protected] test
> jest --passWithNoTests

ts-jest[versions] (WARN) Version 5.0.4 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=4.3.0 <5.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
FAIL Tests/Utils/PingMonitor.test.ts
  ● Test suite failed to run

    Tests/Utils/PingMonitor.test.ts:7:8 - error TS6137: Cannot import type declaration files. Consider importing 'jest' instead of '@types/jest'.

    7 import '@types/jest';

Pull Request Checklist:

  • Please make sure all jobs pass before requesting a review.
  • Put closes #XXXX in your comment to auto-close the issue that your PR fixes (if such).
  • Have you lint your code locally before submission?
  • Did you write tests where appropriate?

Related Issue?

Screenshots (if appropriate):

currentRetryCount?: number;
monitorId?: ObjectID;
isOnlineCheckRequest?: boolean;
deadline?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this?

Copy link
Contributor Author

@fedealconada fedealconada Nov 15, 2023

Choose a reason for hiding this comment

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

https://github.com/danielzzz/node-ping/blob/master/README.md?plain=1#L124

  • @Property {number} deadline - Specify a timeout, in seconds, before ping exits regardless of
    how many packets have been sent or received. In this case ping
    does not stop after count packet are sent, it waits either for
    deadline expire or until count probes are answered or for some
    error notification from network. This option is only available on linux and mac.

I've added it as an optional argument since node-ping does not support timeout for IPv6 but it seems to support deadline

(pingOptions?.timeout?.toNumber() || 5000) / 1000
),
v6: isIPv6,
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ts-ignore?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid using ternary if else since this reduces readability

Copy link
Contributor Author

@fedealconada fedealconada Nov 15, 2023

Choose a reason for hiding this comment

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

Why ts-ignore?

I've added some clarifying comments directly on the code (for devs), but basically it is because probe() expects timeout to be of type (number | undefined) but at the same time, as per their README they say that you can disable timeout by setting it to false.

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