-
Notifications
You must be signed in to change notification settings - Fork 91
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
Introduce Testing to Stacks #1194
Conversation
exclude less files from prettier formatting since running the formatter was breaking the syntax
✅ Deploy Preview for stacks ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary comments while I'm attempting to run locally:
- Can we split out the formatting fixes into it's own commit? I'm totally fine with committing those straight to
develop
without a PR, assuming they're whitespace only changes. - I can't get the tests to run I keep getting
Failed to fetch dynamically imported module
style errors. I'll debug this locally and see what's up there.
The issue is that the path of script modules being pulled in are pointing to the |
Co-authored-by: Ben Kelly <b-kelly@users.noreply.github.com>
Formatting and linting are already isolated in their own commits so I could easily cherry pick them to any other branch. Here are the commits I will cherry pick to the new PR:
Update: this has now been addressed in this PR |
This is probably a windows specific issue. I tested both in macos and ubuntu (for the pipeline) and everything worked out fine. I have a windows VM too - will try to make the time to reproduce your error in that environment. Update: @b-kelly I have described the problem in this issue and made a PR with a fix. In the meantime we point npm to an ad-hoc patched tarball. You should be able to continue your review and run the tests successfully in windows now. |
Remove temp patch when this PR is merged and a new version of the package is released: modernweb-dev/web#2079
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!* I have a minor note on the font-family rule for the visual regression tests, but that's my only note. Great job @giamir!
A few notes for posterity (no action required):
- I love seeing BackstopJS get removed ❤️ It helped at times, but I'm happy to see WTR/Playwright here now.
- I feel like now/soon would be a good time to switch to a component-based file structure. I went searching for the tooltip test, and that little bit of friction reminded me that we should make the switch. I'm glad to make that change soon, as long as we can time it thoughtfully to avoid a ton of conflicts.
* This note is for my own entertainment. Please ignore it.
For years, I've used the phrase "I like it" in place of LGTM. When I heard the phrase in my head, it's always been in this yell, like "I LIKE IT!". I couldn't quite place it, but it finally came to me today. Turns out, I've been hearing the very end of the song Indiscipline from the classic 1981 album Discipline by English progressive rock band King Crimson. Mystery solved!
Thanks @dancormier for the review.
If @b-kelly agrees as well, we should create a task for our backlog and do this even before starting the work to migrate to the monorepo structure. |
Co-authored-by: Dan Cormier <dcormier@stackoverflow.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for getting this in place. I'm very excited about the approach you've implemented here. Other than the missing upstream fix, this looks good to merge!
@@ -0,0 +1 @@ | |||
screenshots/** filter=lfs diff=lfs merge=lfs -text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Nice, this should keep us from accidentally committing images to the git history
</button> | ||
`); | ||
|
||
expect(screen.queryByRole("tooltip")).to.be.null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooh, I like this! Forcing the tests to use the accessibility tree is also a way to force a11y testing in general.
"@typescript-eslint/eslint-plugin": "^5.42.0", | ||
"@typescript-eslint/parser": "^5.44.0", | ||
"backstopjs": "^6.1.4", | ||
"@web/dev-server-esbuild": "^0.3.3", | ||
"@web/dev-server-rollup": "https://github.com/giamir/web/raw/fix-dev-server-rollup/packages/dev-server-rollup/web-dev-server-rollup-0.3.19.tgz", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with this as a short-term fix (until upstream releases a patched version).
No changes necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think so too. We are also covered from a security perspective since we have the content integrity check thanks to the package-lock.json
. I will follow up again about my one-liner PR for WTR.
Co-authored-by: Ben Kelly <b-kelly@users.noreply.github.com>
That is not good, flaky tests are as good as no tests (maybe even worse). I will add an issue for us to explore running the visual regression test suite in a container as Dan suggested. Might use tomorrow's LSG to learn a thing or two about that. |
Thanks @b-kelly for the review. I will go ahead then and merge this and the testing ADR PR. |
This PR builds on top of the PoC Testing PR and supports the Testing Strategy ADR with a concrete implementation.
Context
Prerequisit: we are now tracking visual regression tests baseline images with git lfs (github supports that by default) and you need to have the CLI installed in your local machine to pull and upload those images. You can follow this guide to do so.
Apart from that there is nothing else to learn. You can use git as normal.
There are several file changes because we had many files violating the existing linting rules. You can review those fixes in isolation by checking the individual commits:- fix style rules violations (664bef5)- fix eslint rules violations (53937b3)- fix prettier formatting violations (b5d1aea)Fix existing linting and formatting issues has been now moved into a separate PR.
I also updated the README.md extensively and added a basic GH workflow to build and run tests on every push.
Open Issues and Workarounds
Testing Library Overhead in Browser/ESM Context
Testing Library was initially created to run in a Node.js environment and as a consequence it is relying on several dependencies which supports only CJS and cannot be made ESM-compatible in an easy way by bundler plugins (in our case we use
@rollup/plugin-node-resolve
and@rollup/plugin-commonjs
).By using
@web/test-runner
to run our tests all the code is evaluated in a real browser context and everthing is dynamically imported as an ES module. Since not all our dependencies are ESM we need a bundler (in our caserollup
) which takes care to resolve (plugin-node-resolve) and "esmify" (plugin-commonjs).I had to use npm ovverides to fix a transitive dependency of testing library (
aria-query
) to a version which does not consumedeep-equal
(they introduced that last month in a minor release).deep-equal
is using a couple of old dependencies (likecall-bind
) which rollup was not able to easily "esmify" and resolve. This could be fixed by instructing rollup to do something special about those deps with a small plugin. I did not want get into that yet since we are not even sure if we will keep testing-library (therefore the temporary npm override).Testing library comes with a great a11y-friendly API which is familiar to most frontend developers. It also come with a tooling overhead cost to make it compatible with esm and, as a heads up, if we will use shadow dom in the future we also will have to work around some other limitations.
I personally like very much the structure testing-library bring to our tests and I would be more than willing to pay up some of these costs. I might even foresee a nice opportunity to contribute back to the OS community over time since we are not the only one facing similar challenges (see this Adobe's RFC). That said I would also understand if we want to stay away from this complexity and use directly DOM APIs to query elements under test and simulate interactions.
Web Dev Server Temporary Patches
Web Dev Server (the dev server behind our test runner) is currently unable to execute correctly the latest version of the
@rollup/plugin-commonjs
. This is something I am not too worried about since the maintainer are aware of the issues and already working on a fix. For the time being we have a patch file which we could easily discard once the fix will be released.On top of that we have found an issue where the rollup adapter won't resolve virtual modules in windows environments. A PR with a fix is waiting to be reviewed and merged by the mantainers. In the meantime we point npm to an ad-hoc patched tarball.
Prettier and Style Formatting
I have experienced a strange behavior running prettier against our less files: the formatter will break the style syntax.For the time being I have decided to exclude less files from prettier since they already get some format check with stylelint. We might want to revisit this decision though.
Fix existing linting and formatting issues has been now moved into a separate PR.
Typescript/Eslint checking for test files.
At the moment test files are not linted. This is because I did not want to mess around with the tsconfig.json file. Furthermore I have encountered a strange problem where the assertions (e.g.
expect
) we import from the@open-wc/testing
package seems to don't inherit correctly the relatedChai
types. Further investigation is required although I think this is not very urgent given that we will need to readjust the structure of our repository soon to adhere to the Monorepo ADR. That might be a good time to address this problem.