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

fixed the flaky test for logWebVitalsUtils.test.js #1

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

skholkhojaev
Copy link
Owner

@skholkhojaev skholkhojaev commented Jan 9, 2025

Fixes

  • Resolved flakiness in the Log Web Vitals Utils test by improving assertion flexibility and addressing mock setup issues.

Specific Changes

  • Assertions for lcpEl and lcpElType:
  • Removed hardcoded values
  • Updated to validated that the values are non-empty strings

Copy link

@mokimo mokimo left a comment

Choose a reason for hiding this comment

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

It's always a good habit to add proper description, even if this is a more informal review.

If you also want to create a ticket & track the work you can also do that. It's not strictly required, but a good habit to get into nonetheless!

Comment on lines 22 to 39
window.performance.getEntriesByType = () => [
{
startTime: 0,
name: '/test/utils/mocks/media_.png',
type: 'paint',
duration: 10,
},
];

const parentElement = document.createElement('div');
parentElement.id = 'parent';

const lcpElement = document.createElement('div');
lcpElement.id = 'lcpElement';
lcpElement.textContent = 'LCP Element';

parentElement.appendChild(lcpElement);
document.body.appendChild(parentElement);
Copy link

Choose a reason for hiding this comment

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

I would assume document.body.innerHTML = await readFile({ path: './mocks/body.html' }); already handles adding the image.

If you mock the window.performance.getEntriesByType, I'd do that in a beforeEach block and "reset/restore" it in an afterEach block - otherwise you might affect other tests by building up test state and connected tests.

Since it seems you are not trying to go with this approach anymore, you can also delete those lines again.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Noted 📓 and added the beforeEach and afterEach

expect(vitals).to.have.property('lcpEl');
expect(vitals.lcpEl).to.be.a('string').that.is.not.empty;
expect(vitals).to.have.property('lcpElType');
expect(vitals.lcpElType).to.be.oneOf(['img', 'div', 'p', 'span', '']);
Copy link

Choose a reason for hiding this comment

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

I'd probably also just verify it has an lcpType and not neccesarily test if it's oneOf.
Reason being, if chrome or whatever browser decides it changes it algorithm or the mock on L12 is changed, this will break, despite the functionality still being correct

@skholkhojaev skholkhojaev requested a review from mokimo January 10, 2025 12:15
@mokimo
Copy link

mokimo commented Jan 10, 2025

Just FYI for repo-sanity, usually u'd just call your fork milo as well - such as https://github.com/mokimo/milo/pulls rather than creating a new repo per fix. You'd use branches per fix, not repositories per fix

@skholkhojaev
Copy link
Owner Author

Just FYI for repo-sanity, usually u'd just call your fork milo as well - such as https://github.com/mokimo/milo/pulls rather than creating a new repo per fix. You'd use branches per fix, not repositories per fix

that makes sense, i'll change it to milo 👍

Copy link

@mokimo mokimo left a comment

Choose a reason for hiding this comment

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

Cool, I think it's ready to be raised to (adobecom/)milo as real pull request

@skholkhojaev skholkhojaev merged commit c9ca27d into stage Jan 13, 2025
skholkhojaev added a commit that referenced this pull request Jan 31, 2025
…obecom#3549)

* fixed the flaky test for logWebVitalsUtils.test.js (#1)

* fixed the flaky test

* move performance mock to beforeEach/afterEach for isolation, simplify lcpElType check

* removed unused code

* fixed the same issue in logWebVitals.test.js and reverted unnecessary changes

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* removed dependency on gist.github.com by mocking script request

* replaced setTimeout to prevent flakiness

* Replaced Promise.resolve().then() with setTimeout()

* earlier return for if statement

* Improve callback matching in script mock

* improve event loop handling

* Replaced IIFE with async
skholkhojaev added a commit that referenced this pull request Feb 19, 2025
* fixed the flaky test for logWebVitalsUtils.test.js (#1)

* fixed the flaky test

* move performance mock to beforeEach/afterEach for isolation, simplify lcpElType check

* removed unused code

* fixed the same issue in logWebVitals.test.js and reverted unnecessary changes

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* Update fstab.yaml

* enhanced tool tips Unit tests

* added assertions and isolated DOM state

* changed unnecessary async to sync

* added loadIcons for duplicate test

* tooltip should be visible on hover

* added a test case for visibility of tooltip

* testcase for tooltip visibility

* Changes visibility test case & gave appropriate name to tests

* Update test/features/icons/icons.test.js

Co-authored-by: Robert Bogos <146744221+robert-bogos@users.noreply.github.com>

---------

Co-authored-by: Robert Bogos <146744221+robert-bogos@users.noreply.github.com>
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