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

Add unit tests to bindReporter #576

Merged
merged 5 commits into from
Dec 9, 2024

Conversation

nucliweb
Copy link
Contributor

@nucliweb nucliweb commented Dec 9, 2024

In this Pull Request

Add unit tests to bindReporter

The let fixDelta = reporters[1].delta.toFixed(2) avoids floating point precision issues in the test assertion by rounding the delta value to 2 decimal places before comparing it.

Test error

✖ should calculate delta correctly between reports (1.825833ms)
  AssertionError [ERR_ASSERTION]: 0.04999999999999999 == 0.05
      at TestContext.<anonymous> (file:///.../web-vitals/test/unit/bindReporter-test.js:104:14)
      at Test.runInAsyncScope (node:async_hooks:203:9)
      at Test.run (node:internal/test_runner/test:631:25)
      at Test.start (node:internal/test_runner/test:542:17)
      at node:internal/test_runner/test:946:71
      at node:internal/per_context/primordials:487:82
      at new Promise (<anonymous>)
      at new SafePromise (node:internal/per_context/primordials:455:29)
      at node:internal/per_context/primordials:487:9
      at Array.map (<anonymous>) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: 0.04999999999999999,
    expected: 0.05,
    operator: '=='
  }

@tunetheweb
Copy link
Member

Love having more tests!!!

However, not loving the toFixed(2) change. Especially as this'll narrow LCP to 0.1 second precision?

The metric.delta = Number(delta.toFixed(2))) change avoids floating point precision issues in the test assertion by rounding the delta value to 2 decimal places before comparing it.

Why can't we do this rounding in the test?

@nucliweb
Copy link
Contributor Author

nucliweb commented Dec 9, 2024

Yes, I'll move to the test 👍

@nucliweb
Copy link
Contributor Author

nucliweb commented Dec 9, 2024

@tunetheweb done,

@tunetheweb tunetheweb merged commit 6721668 into GoogleChrome:main Dec 9, 2024
6 checks passed
@nucliweb nucliweb deleted the feat/bind-reporter-test branch December 9, 2024 23:08
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