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 incorrect validation of time values in JUnit Reporter #2965

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

- [Multi DataSource] Add unit test coverage for Update Data source management stack ([#2567](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2567))
- [BWC Tests] Add BWC tests for 2.5.0 ([#2890](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2890))
- Fix incorrect validation of time values in JUnit Reporter ([#2965](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2965))

## [2.x]

Expand Down
5 changes: 3 additions & 2 deletions src/dev/jest/junit_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export default class JestJUnitReporter {
{ skipNullAttributes: true }
);

const msToIso = (ms) => (ms ? new Date(ms).toISOString().slice(0, -5) : undefined);
const msToSec = (ms) => (ms ? (ms / 1000).toFixed(3) : undefined);
const isNumeric = (val) => !isNaN(parseFloat(val)) && isFinite(val);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the !isNaN check if isFinite also return false if the number is NaN or undefined? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is to weed out null, Infinity, and -Infinity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

btw, nice to hear from you ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

It is to weed out null, Infinity, and -Infinity.

Ah, got it. So I think the equivalent would be val !== null && isFinite(val) then right? Not a big difference but we could avoid the parseFloat?

const msToIso = (ms) => (isNumeric(ms) ? new Date(ms).toISOString().slice(0, -5) : undefined);
const msToSec = (ms) => (isNumeric(ms) ? (ms / 1000).toFixed(3) : undefined);

root.att({
name: 'jest',
Expand Down