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

Update tests for Nuxt 3 migration #3667

Merged
merged 2 commits into from Jan 18, 2024
Merged

Update tests for Nuxt 3 migration #3667

merged 2 commits into from Jan 18, 2024

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Jan 15, 2024

Fixes

Split from #3646 by @obulat
This PR can be merged to main because it works with both Nuxt 2 and Nuxt 3

Description

This PR moves all analytics tests from the unit to Playwright E2E tests. It makes the tests more reliable and also avoid the need to mock the analytics requests in the unit tests (which was causing problems in @nuxt/test-utils).

The Playwright test setup was refactored to ensure all tests were well set up. Often, Playwright test flakiness is caused by the fact that we are trying to interact with the page before it's been hydrated (hydration means adding the JavaScript event handlers to the server-rendered HTML). So, Playwright was clicking on buttons, but nothing would happen since they didn't yet have event handlers. I've set the button state to disabled before they are hydrated (as suggested by Playwright docs) in the Nuxt 3 migration PR. Here, I just added the proper setup for all tests and waited for the "enabled" state.

To make the cookies for the UI state easier to handle with the new useCookie composable in Nuxt 3, I combined all of them in a single ui cookie object. This change is added here to the UI store, tests, and the initFromCookies calls.

For global audio tests, I used HAR recordings to save the audio file, and stop requesting it from the provider on every test run (and prevent flakiness).

The bulk of changed files are the response tapes: I added the CORS header as there were too many CORS-related errors in the tests locally, and sometimes in CI.

Some other changes were related to code cleanup, refactoring to extract common functionality, and removing warnings.

I also normalized the peaks in the audio tapes, reducing the number of peaks for each audio to a maximum of 200 (from ~1000), which helped create this image:

Screenshot 2024-01-15 at 8 41 36 PM

Testing Instructions

CI should pass, and the test changes should make sense.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@github-actions github-actions bot added the 🧱 stack: frontend Related to the Nuxt frontend label Jan 15, 2024
@openverse-bot openverse-bot added the 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work label Jan 15, 2024
@obulat obulat added 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟧 priority: high Stalls work on the project or its dependents and removed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Jan 15, 2024
@obulat obulat marked this pull request as ready for review January 15, 2024 16:58
@obulat obulat requested a review from a team as a code owner January 15, 2024 16:58
@obulat obulat force-pushed the nuxt3/update_tests branch 9 times, most recently from 04a1a14 to 60e9c24 Compare January 16, 2024 10:25
Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

The changes to the code, in src/ look good. Thanks for the useHydrating composable.

I'll be honest, I didn't do a very thorough job of reading each line in the diff for the test/ directory. It's a lot to take in. But I agree with your summary of the changes in the PR description, and the tests are passing, so I'm approving this.

Copy link
Contributor

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

The test simplifications look great! Similarly it's difficult to introspect all the test changes, but thank you for all your work on this 🚀 The app continues to run as expected locally, this is good to go IMO!

Use har for audio tests to prevent provider requests and flakiness
Convert ui cookies for ease of use
Move analytics tests from unit tests to e2e tests
Disable buttons until hydrated

Signed-off-by: Olga Bulat <obulat@gmail.com>
Signed-off-by: Olga Bulat <obulat@gmail.com>
@obulat obulat merged commit e747803 into main Jan 18, 2024
38 checks passed
@obulat obulat deleted the nuxt3/update_tests branch January 18, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

4 participants