Skip to content

Conversation

@bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Jan 19, 2022

Numbers in JavaScript can have precision issues due to how they are encoded. This shows up in snapshot tests sometimes with values like 0.0009999999999999992, which makes the tests hard to read and visually diff.

This PR adds a new snapshot serializers which clamps numbers at 3 decimal points (e.g. the above number 0.0009999999999999992 is serialized as 0.001). This new serializer does not impact non-numeric values, integers, and special numbers like NaN and Infinity.

The change was done in three commits to simplify the review process:

  • 63e2df6: All serializers were moved into their own folder (to make tests easier to browse)
  • 99ed9c7: A new numeric serializer was added
  • 984f3f5: Snapshots were updated to account for the new number format

@sizebot
Copy link

sizebot commented Jan 19, 2022

Comparing: 790b524...984f3f5

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 129.72 kB 129.72 kB = 41.58 kB 41.58 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 134.86 kB 134.86 kB = 43.11 kB 43.11 kB
facebook-www/ReactDOM-prod.classic.js = 428.15 kB 428.15 kB = 78.69 kB 78.69 kB
facebook-www/ReactDOM-prod.modern.js = 417.87 kB 417.87 kB = 77.23 kB 77.23 kB
facebook-www/ReactDOMForked-prod.classic.js = 428.15 kB 428.15 kB = 78.70 kB 78.70 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 984f3f5

@bvaughn bvaughn merged commit a637084 into facebook:main Jan 20, 2022
@bvaughn bvaughn deleted the devtools-snapshot-tests-numbers-toFixed branch January 20, 2022 20:52
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
…k#23139)

Numbers in JavaScript can have precision issues due to how they are encoded. This shows up in snapshot tests sometimes with values like 0.0009999999999999992, which makes the tests hard to read and visually diff.

This PR adds a new snapshot serializers which clamps numbers at 3 decimal points (e.g. the above number 0.0009999999999999992 is serialized as 0.001). This new serializer does not impact non-numeric values, integers, and special numbers like NaN and Infinity.
nevilm-lt pushed a commit to nevilm-lt/react that referenced this pull request Apr 22, 2022
…k#23139)

Numbers in JavaScript can have precision issues due to how they are encoded. This shows up in snapshot tests sometimes with values like 0.0009999999999999992, which makes the tests hard to read and visually diff.

This PR adds a new snapshot serializers which clamps numbers at 3 decimal points (e.g. the above number 0.0009999999999999992 is serialized as 0.001). This new serializer does not impact non-numeric values, integers, and special numbers like NaN and Infinity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Component: Developer Tools React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants