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

Prevent accidentally committing focused test selectors #2199

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

sarayourfriend
Copy link
Collaborator

Fixes

Follow up to #2194 by @obulat

Description

The related PR removes an accidentally committed .only focused test selector. We can easily prevent accidental commits like that in the future with the Jest ESLint plugin and with Playwright's own forbidOnly setting.

This PR adds the Jest plugin and enables Playwright's forbidOnly setting in CI.

Testing Instructions

Check out the changes made to appease the new ESLint plugin. I think they are good rules. I opened a discussion about whether relying on testing-library's get* function's error handling behaviour as an implicit assertion is a good idea long-term: #2198

For now I've just selectively disabled the expect-expect check or expanded the assert function list for modules that heavily rely on that.

The plugin caught a handful of tests that truly were incorrect, either because they had no assertions at all (!!) or because they were using expect incorrectly (like expect(predicate) rather than expect(someValue).predicate(), the former does nothing).

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.
  • [N/A] 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.

@sarayourfriend sarayourfriend added 🟨 priority: medium Not blocking but should be addressed soon 🤖 aspect: dx Concerns developers' experience with the codebase 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🧱 stack: frontend Related to the Nuxt frontend skip-changelog labels May 26, 2023
@sarayourfriend sarayourfriend requested a review from a team as a code owner May 26, 2023 00:51
@github-actions github-actions bot added 🏷 status: label work required Needs proper labelling before it can be worked on 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels May 26, 2023
@github-actions
Copy link

github-actions bot commented May 26, 2023

Size Change: 0 B

Total Size: 839 kB

ℹ️ View Unchanged
Filename Size
./frontend/.nuxt/dist/client/234.js 272 B
./frontend/.nuxt/dist/client/234.modern.js 277 B
./frontend/.nuxt/dist/client/235.js 1.85 kB
./frontend/.nuxt/dist/client/app.js 123 kB
./frontend/.nuxt/dist/client/app.modern.js 115 kB
./frontend/.nuxt/dist/client/commons/app.js 90.2 kB
./frontend/.nuxt/dist/client/commons/app.modern.js 78.5 kB
./frontend/.nuxt/dist/client/commons/components/v-search-grid/pages/search.js 5.17 kB
./frontend/.nuxt/dist/client/commons/components/v-search-grid/pages/search.modern.js 5.61 kB
./frontend/.nuxt/dist/client/components/loading-icon.js 766 B
./frontend/.nuxt/dist/client/components/loading-icon.modern.js 772 B
./frontend/.nuxt/dist/client/components/table-sort-icon.js 514 B
./frontend/.nuxt/dist/client/components/table-sort-icon.modern.js 519 B
./frontend/.nuxt/dist/client/components/v-all-results-grid.js 5.75 kB
./frontend/.nuxt/dist/client/components/v-all-results-grid.modern.js 5.62 kB
./frontend/.nuxt/dist/client/components/v-audio-cell.js 422 B
./frontend/.nuxt/dist/client/components/v-audio-cell.modern.js 427 B
./frontend/.nuxt/dist/client/components/v-audio-details.js 1.81 kB
./frontend/.nuxt/dist/client/components/v-audio-details.modern.js 1.77 kB
./frontend/.nuxt/dist/client/components/v-audio-track-skeleton.js 1.02 kB
./frontend/.nuxt/dist/client/components/v-audio-track-skeleton.modern.js 1.02 kB
./frontend/.nuxt/dist/client/components/v-audio-track.js 5.33 kB
./frontend/.nuxt/dist/client/components/v-audio-track.modern.js 5.29 kB
./frontend/.nuxt/dist/client/components/v-back-to-search-results-link.js 637 B
./frontend/.nuxt/dist/client/components/v-back-to-search-results-link.modern.js 642 B
./frontend/.nuxt/dist/client/components/v-bone.js 688 B
./frontend/.nuxt/dist/client/components/v-bone.modern.js 691 B
./frontend/.nuxt/dist/client/components/v-box-layout.js 1.28 kB
./frontend/.nuxt/dist/client/components/v-box-layout.modern.js 1.28 kB
./frontend/.nuxt/dist/client/components/v-content-link.js 1.04 kB
./frontend/.nuxt/dist/client/components/v-content-link.modern.js 1.04 kB
./frontend/.nuxt/dist/client/components/v-content-page.js 524 B
./frontend/.nuxt/dist/client/components/v-content-page.modern.js 528 B
./frontend/.nuxt/dist/client/components/v-content-report-button.js 493 B
./frontend/.nuxt/dist/client/components/v-content-report-button.modern.js 496 B
./frontend/.nuxt/dist/client/components/v-content-report-form.js 3.31 kB
./frontend/.nuxt/dist/client/components/v-content-report-form.modern.js 3.19 kB
./frontend/.nuxt/dist/client/components/v-content-report-popover.js 3.78 kB
./frontend/.nuxt/dist/client/components/v-content-report-popover.modern.js 3.65 kB
./frontend/.nuxt/dist/client/components/v-copy-button.js 4 kB
./frontend/.nuxt/dist/client/components/v-copy-button.modern.js 4 kB
./frontend/.nuxt/dist/client/components/v-copy-license.js 2.09 kB
./frontend/.nuxt/dist/client/components/v-copy-license.modern.js 2.06 kB
./frontend/.nuxt/dist/client/components/v-dmca-notice.js 793 B
./frontend/.nuxt/dist/client/components/v-dmca-notice.modern.js 798 B
./frontend/.nuxt/dist/client/components/v-error-image.js 2.6 kB
./frontend/.nuxt/dist/client/components/v-error-image.modern.js 2.58 kB
./frontend/.nuxt/dist/client/components/v-error-section.js 372 B
./frontend/.nuxt/dist/client/components/v-error-section.modern.js 377 B
./frontend/.nuxt/dist/client/components/v-external-search-form.js 1.89 kB
./frontend/.nuxt/dist/client/components/v-external-search-form.modern.js 1.87 kB
./frontend/.nuxt/dist/client/components/v-external-source-list.js 894 B
./frontend/.nuxt/dist/client/components/v-external-source-list.modern.js 897 B
./frontend/.nuxt/dist/client/components/v-full-layout.js 1.56 kB
./frontend/.nuxt/dist/client/components/v-full-layout.modern.js 1.55 kB
./frontend/.nuxt/dist/client/components/v-grid-skeleton.js 1.62 kB
./frontend/.nuxt/dist/client/components/v-grid-skeleton.modern.js 1.62 kB
./frontend/.nuxt/dist/client/components/v-home-gallery.js 4.91 kB
./frontend/.nuxt/dist/client/components/v-home-gallery.modern.js 4.91 kB
./frontend/.nuxt/dist/client/components/v-homepage-content.js 1.77 kB
./frontend/.nuxt/dist/client/components/v-homepage-content.modern.js 1.74 kB
./frontend/.nuxt/dist/client/components/v-image-carousel.js 4.73 kB
./frontend/.nuxt/dist/client/components/v-image-carousel.modern.js 4.7 kB
./frontend/.nuxt/dist/client/components/v-image-cell.js 1.66 kB
./frontend/.nuxt/dist/client/components/v-image-cell.modern.js 1.65 kB
./frontend/.nuxt/dist/client/components/v-image-details.js 1.42 kB
./frontend/.nuxt/dist/client/components/v-image-details.modern.js 1.41 kB
./frontend/.nuxt/dist/client/components/v-image-grid.js 3.9 kB
./frontend/.nuxt/dist/client/components/v-image-grid.modern.js 3.78 kB
./frontend/.nuxt/dist/client/components/v-license-tab-panel.js 642 B
./frontend/.nuxt/dist/client/components/v-license-tab-panel.modern.js 649 B
./frontend/.nuxt/dist/client/components/v-load-more.js 846 B
./frontend/.nuxt/dist/client/components/v-load-more.modern.js 741 B
./frontend/.nuxt/dist/client/components/v-media-license.js 827 B
./frontend/.nuxt/dist/client/components/v-media-license.modern.js 835 B
./frontend/.nuxt/dist/client/components/v-media-reuse.js 2.68 kB
./frontend/.nuxt/dist/client/components/v-media-reuse.modern.js 2.65 kB
./frontend/.nuxt/dist/client/components/v-media-tag.js 416 B
./frontend/.nuxt/dist/client/components/v-media-tag.modern.js 421 B
./frontend/.nuxt/dist/client/components/v-modal.js 1 kB
./frontend/.nuxt/dist/client/components/v-modal.modern.js 995 B
./frontend/.nuxt/dist/client/components/v-no-results.js 818 B
./frontend/.nuxt/dist/client/components/v-no-results.modern.js 815 B
./frontend/.nuxt/dist/client/components/v-radio.js 1 kB
./frontend/.nuxt/dist/client/components/v-radio.modern.js 1.01 kB
./frontend/.nuxt/dist/client/components/v-related-audio.js 1.29 kB
./frontend/.nuxt/dist/client/components/v-related-audio.modern.js 1.29 kB
./frontend/.nuxt/dist/client/components/v-related-images.js 1.1 kB
./frontend/.nuxt/dist/client/components/v-related-images.modern.js 1.1 kB
./frontend/.nuxt/dist/client/components/v-report-desc-form.js 976 B
./frontend/.nuxt/dist/client/components/v-report-desc-form.modern.js 981 B
./frontend/.nuxt/dist/client/components/v-row-layout.js 1.68 kB
./frontend/.nuxt/dist/client/components/v-row-layout.modern.js 1.68 kB
./frontend/.nuxt/dist/client/components/v-scroll-button.js 825 B
./frontend/.nuxt/dist/client/components/v-scroll-button.modern.js 829 B
./frontend/.nuxt/dist/client/components/v-search-grid.js 6.87 kB
./frontend/.nuxt/dist/client/components/v-search-grid.modern.js 6.22 kB
./frontend/.nuxt/dist/client/components/v-search-results-title.js 618 B
./frontend/.nuxt/dist/client/components/v-search-results-title.modern.js 621 B
./frontend/.nuxt/dist/client/components/v-server-timeout.js 299 B
./frontend/.nuxt/dist/client/components/v-server-timeout.modern.js 303 B
./frontend/.nuxt/dist/client/components/v-sketch-fab-viewer.js 1.02 kB
./frontend/.nuxt/dist/client/components/v-sketch-fab-viewer.modern.js 914 B
./frontend/.nuxt/dist/client/components/v-snackbar.js 1.16 kB
./frontend/.nuxt/dist/client/components/v-snackbar.modern.js 1.17 kB
./frontend/.nuxt/dist/client/components/v-sources-table.js 15.1 kB
./frontend/.nuxt/dist/client/components/v-sources-table.modern.js 15.2 kB
./frontend/.nuxt/dist/client/components/v-warning-suppressor.js 306 B
./frontend/.nuxt/dist/client/components/v-warning-suppressor.modern.js 311 B
./frontend/.nuxt/dist/client/pages/about.js 1.39 kB
./frontend/.nuxt/dist/client/pages/about.modern.js 1.4 kB
./frontend/.nuxt/dist/client/pages/audio/_id/index.js 6.09 kB
./frontend/.nuxt/dist/client/pages/audio/_id/index.modern.js 5.89 kB
./frontend/.nuxt/dist/client/pages/external-sources.js 1.55 kB
./frontend/.nuxt/dist/client/pages/external-sources.modern.js 1.56 kB
./frontend/.nuxt/dist/client/pages/feedback.js 1.34 kB
./frontend/.nuxt/dist/client/pages/feedback.modern.js 1.34 kB
./frontend/.nuxt/dist/client/pages/image/_id/index.js 7.06 kB
./frontend/.nuxt/dist/client/pages/image/_id/index.modern.js 6.77 kB
./frontend/.nuxt/dist/client/pages/image/_id/report.js 5 kB
./frontend/.nuxt/dist/client/pages/image/_id/report.modern.js 4.74 kB
./frontend/.nuxt/dist/client/pages/index.js 7.03 kB
./frontend/.nuxt/dist/client/pages/index.modern.js 6.96 kB
./frontend/.nuxt/dist/client/pages/preferences.js 1.3 kB
./frontend/.nuxt/dist/client/pages/preferences.modern.js 1.3 kB
./frontend/.nuxt/dist/client/pages/privacy.js 1.23 kB
./frontend/.nuxt/dist/client/pages/privacy.modern.js 1.24 kB
./frontend/.nuxt/dist/client/pages/search-help.js 1.6 kB
./frontend/.nuxt/dist/client/pages/search-help.modern.js 1.58 kB
./frontend/.nuxt/dist/client/pages/search.js 2.2 kB
./frontend/.nuxt/dist/client/pages/search.modern.js 2.04 kB
./frontend/.nuxt/dist/client/pages/search/audio.js 3.67 kB
./frontend/.nuxt/dist/client/pages/search/audio.modern.js 3.55 kB
./frontend/.nuxt/dist/client/pages/search/image.js 545 B
./frontend/.nuxt/dist/client/pages/search/image.modern.js 547 B
./frontend/.nuxt/dist/client/pages/search/index.js 443 B
./frontend/.nuxt/dist/client/pages/search/index.modern.js 447 B
./frontend/.nuxt/dist/client/pages/search/model-3d.js 242 B
./frontend/.nuxt/dist/client/pages/search/model-3d.modern.js 246 B
./frontend/.nuxt/dist/client/pages/search/search-page.types.js 266 B
./frontend/.nuxt/dist/client/pages/search/search-page.types.modern.js 270 B
./frontend/.nuxt/dist/client/pages/search/video.js 239 B
./frontend/.nuxt/dist/client/pages/search/video.modern.js 243 B
./frontend/.nuxt/dist/client/pages/sources.js 1.51 kB
./frontend/.nuxt/dist/client/pages/sources.modern.js 1.52 kB
./frontend/.nuxt/dist/client/runtime.js 2.71 kB
./frontend/.nuxt/dist/client/runtime.modern.js 2.72 kB
./frontend/.nuxt/dist/client/vendors/app.js 64.7 kB
./frontend/.nuxt/dist/client/vendors/app.modern.js 63.8 kB

compressed-size-action

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.

LGTM. Also what's up with #1130?

@sarayourfriend
Copy link
Collaborator Author

@dhruvkb I started rebasing that PR earlier this week and need to get back to it. I basically just need to start back from scratch rather than trying to apply it directly here. I think the changes in here (hoisting the eslint config for tests up) will actually make it easier. Something I ran into and kept trying to work around in that PR was weird dependency installation issues for nested configurations.

If we run eslint in a local hook (as discussed in #2197) that would also help as installing a local package also took a good bit of fiddling and in the end didn't really work correctly all the time.

Hopefully next week I can get that other eslint PR working fully and we can write some more abstract custom rules 🤞

@obulat obulat removed 🏷 status: label work required Needs proper labelling before it can be worked on 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels May 26, 2023
@zackkrida
Copy link
Member

@sarayourfriend I'm seeing a discrepancy between the PR description and the actual diff. The description mentions adding and configuring the Jest ESLint plugin while the diff only shows the addition of custom rules for disallowing the focused test selectors.

I'm happy with either approach, just want to make sure I review the intended one.

@sarayourfriend
Copy link
Collaborator Author

Shoot, I forgot to push 🤦 Changes are up now, apologies for the confusion.

Comment on lines -101 to -106
{
selector:
"ImportDeclaration[source.value='@vue/test-utils']:has(ImportSpecifier[local.name='shallowMount'])",
message:
"Do not use @vue/test-utils' `shallowMount`. Use @testing-library/vue's `render` instead.",
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This rule is moved to the unit test scope in overrides further down in this file.

Comment on lines +188 to 212
env: { jest: true },
files: ["frontend/test/unit/**"],
plugins: ["jest"],
extends: ["plugin:jest/recommended"],
rules: {
"import/no-named-as-default-member": ["off"],
"@intlify/vue-i18n/no-raw-text": ["off"],
"no-restricted-imports": [
"error",
{
name: "pinia",
message:
"Please import pinia test utils from `~~/test/unit/test-utils/pinia`. The test-utils version ensures proper setup of universally necessary Nuxt context mocks.",
},
],
"no-restricted-syntax": [
"error",
{
selector:
"ImportDeclaration[source.value='@vue/test-utils']:has(ImportSpecifier[local.name='shallowMount'])",
message:
"Do not use @vue/test-utils' `shallowMount`. Use `~~/test/unit/test-utils/render` instead which includes helpful context setup or @testing-library/vue's `render` directly.",
},
],
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using a single ESLint configuration with overrides to configure sub-folder behaviour is ultimately easier to understand, I think, than nested configurations. We also had incorrectly configured the nested configuration with an unnecessary extends setting, (which causes a new configuration to be created rather than a merged one), showing that it's harder to maintain. It also makes it easier to reason about which rules apply where and which ones are shared without having to jump between multiple files. We can move the other ESLint configuration files into overrides in separate PRs.

@@ -26,6 +26,7 @@ const pwCommand =
process.env.FASTSTART !== "false" ? "start:playwright" : "prod:playwright"

const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This allows it to pass locally but fails CI if .only is present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would we allow it to pass locally if .only is present but fail on CI? Is it time consuming to have this check run locally? And do you think it makes sense to add a comment as to why this was added here?

Comment on lines +103 to +105
expect(playStub).toHaveBeenCalledTimes(1)
expect(pauseStub).toHaveBeenCalledTimes(1)
expect(getByText(/Reproduction not allowed./i)).toBeVisible()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

None of these expect calls returned promises.

Comment on lines +24 to +28
expect(() => {
screen.getByText(props.audio.title)
screen.getByLabelText("Attribution-NonCommercial-Share-Alike")
screen.getByText("Music")
}).not.toThrow()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a workaround related to #2198. I think it's better than setting each of these as assert functions using the comment approach in other modules.

A potentially better alternative is to change them to query* functions and assert .not.toBeNull() on them, but I'll let the discussion I linked play out before we make concerted refactors to these. We may decide on a different approach altogether.

@@ -15,7 +17,7 @@ import VTabPanel from "~/components/VTabs/VTabPanel.vue"
* @param {string} text
* @param {boolean?} visibility
*/
const expectVisibitility = (screen, text, visibility = true) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function name was misspelled.

Comment on lines -258 to -259
})
describe("actions", () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This describe block had the same name as the previous block so I merged them.

Comment on lines 104 to 106
const exepectedStoreValue =
key === "isMobileUi" ? false : initialState[key]
expect(uiStore[key]).toEqual(exepectedStoreValue)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This code is equivalent to the original but prevents the no-conditional-expect rule from needing to be disabled twice (or at all).

Comment on lines +67 to +71
expect(document.getElementsByTagName("a")).not.toHaveLength(0)
document.body.innerHTML = getAttribution(mediaItem, i18n, {
isPlaintext: true,
})
expect(document.getElementsByTagName("a").length === 0)
expect(document.getElementsByTagName("a")).toHaveLength(0)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original version of these assertions were noops. expect() by itself does nothing. Here's an excellent example of the Jest plugin catching incorrect, false positive (and therefore dangerous because they create false confidence) tests.

Comment on lines +203 to +211
"no-restricted-syntax": [
"error",
{
selector:
"ImportDeclaration[source.value='@vue/test-utils']:has(ImportSpecifier[local.name='shallowMount'])",
message:
"Do not use @vue/test-utils' `shallowMount`. Use `~~/test/unit/test-utils/render` instead which includes helpful context setup or @testing-library/vue's `render` directly.",
},
],
Copy link
Member

Choose a reason for hiding this comment

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

OOOH this is perfect, I need this in #2196

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

According to CI there are two remaining unit test failures but the overall approach here and restructuring of the eslint configurations is excellent!

@openverse-bot
Copy link
Collaborator

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@zackkrida
@AetherUnbound
@obulat
@dhruvkb
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was ready for review 4 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@sarayourfriend, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the operation that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

Comment on lines +154 to +158
// This test is broken (for some reason clickOutside does not appear to actually cause a click
// to happen in this case).
// https://github.com/WordPress/openverse/issues/2220
// eslint-disable-next-line jest/no-disabled-tests
it.skip("should hide the popover if a click happens outside the popover by default", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// This test is broken (for some reason clickOutside does not appear to actually cause a click
// to happen in this case).
// https://github.com/WordPress/openverse/issues/2220
// eslint-disable-next-line jest/no-disabled-tests
it.skip("should hide the popover if a click happens outside the popover by default", async () => {
it("should hide the popover if a click happens outside the popover by default", async () => {

The fix has been merged.

Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Thank you for all your work on improving our confidence in tests and code changes, @sarayourfriend . All the changes look correct

Copy link
Member

@zackkrida zackkrida left a comment

Choose a reason for hiding this comment

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

Tested a number of the new linting rules to make sure they work, and also tried setting forbidOnly to true locally and running the suite to confirm it fails. Works perfectly. Errors look like this for anyone curious:

Error: focused item found in the --forbid-only mode: "all results grid keyboard accessibility test should open audio results as links"

@zackkrida
Copy link
Member

zackkrida commented Jun 2, 2023

@sarayourfriend I'm going to merge this in the interest of getting #2196 undrafted and so I can finish it while it's fresh in my memory. The changes here will be relevant there. Thought it would cause merge conflicts but there are none 👍

@zackkrida zackkrida merged commit 2b58f9e into main Jun 2, 2023
@zackkrida zackkrida deleted the add/disallow-commit-test-only branch June 2, 2023 19:34
Copy link
Collaborator

@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.

All of the test changes make sense to me! I have a few questions but nothing to block a merge. I'm impressed by how specific the ESLint rules can get!

@@ -26,6 +26,7 @@ const pwCommand =
process.env.FASTSTART !== "false" ? "start:playwright" : "prod:playwright"

const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why would we allow it to pass locally if .only is present but fail on CI? Is it time consuming to have this check run locally? And do you think it makes sense to add a comment as to why this was added here?

@@ -10,6 +10,7 @@ addAliases({
})

const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same note here as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

.only is useful to have locally if you're debugging a single, specific test, for example, in debug mode, where it runs in a "headed" browser that you can poke around the context with: https://playwright.dev/docs/debug

In that setting, if you haven't selected a single test to run, the runner is going to run everything in the module, requiring you to try check which test is running each time and pass it until you get to the one you want.

That's to say: only is useful locally, but harmful if committed and forbidding it in CI is an easy way to catch when it is committed. Additionally, something that isn't necessarily obvious, is that Playwright and Jest are distinct test runners. Even though they look very similar in API, they have certain differences that will make the eslint-plugin-jest incompatible (or at least flaky) with Playwright. It would be better if our configuration didn't let you commit the test selection, though, and luckily there is a Playwright-specific ESLint plugin with the same no-focused-test rule that the Jest plugin provides. I've opened an issue to add it here: #2312. That would give us a whole host of helpful checks, but also prevent .only from being committed at all in our Playwright tests (rather than just failing in CI).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Woah, okay that makes sense! Thanks for the helpful context!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 aspect: dx Concerns developers' experience with the codebase 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟨 priority: medium Not blocking but should be addressed soon skip-changelog 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants