Repository navigation
Adding Cypress for browser-based component unit testing - #5042
Conversation
…rap as well as a component test example for the same
I'd vote no for now/for the initial Cypress setup, and investigate future extra Cypress plugins as we decide we need them. Cypress can do a lot of cool things, but I generally prefer adding things incrementally and as there's a strong use case for it, rather than all at once. As another example of something Cypress could maybe someday do: there's an existing cypress-axe plugin that could we could opt to switch to if we prefer having all our E2E tests in one place and using one test framework, or if we prefer its violation reporting/debugging process. But it should definitely be evaluated on a case-by-case basis.
I would vote against setting up standard E2E integration tests for now and for solely using the component test runner to start with. As someone who has spent an unfortunately high amount of time debugging varying Selenium or Cypress flakes - it's the nature/terrain of E2E testing that you're going to run into bizarre and hard-to-replicate intermittent failures (partially due to 3rd party deps/load times, and partially due to how insanely fast the automatic test runner goes compared to a real human person). The component test runner however looks like an amazing way to mitigate that and isolate/sandbox some amount of flaking, and is agruably much more effective for EUI/any component library. For an actual solution definitely they'd want standard E2E tests, for us, the CTR couldn't have come out at a more opportune time. The most likely scenario I can think of that we would potentially want automated E2E tests for (based on what I've heard during onboarding/roadmap discussions) is if we're testing how EUI integrates into Kibana, Cloud, or other platforms. IIRC we're still figuring out how that would work in terms of CI and so forth, so that might be a ways off yet, and would likely need more discussion to figure out the exact goals (what regressions/breakages can we hope to catch?)
+++, would love to see this documented in the testing wiki. In terms of developer experience and speed, my vote personally would be to default to jest/unit tests first and only write Cypress component tests for functionality that jsdom/enzyme can't easily mock (focus, portals, 3rd party dependencies, native DOM behaviors, etc. - a comprehensive list would be fantastic if we can brainstorm one). I also think whether we prefer Cypress vs. Jest will depend on exactly what kind of bugs, issues, or regressions we're attempting to catch (or even which come up organically over time). If we end up seeing more bizarre browser-level bugs/interactions that jsdom can't realistically replicate, I think we'll naturally end up with more Cypress component tests over time (e.g., this recent PR from Greg would have been a great candidate for a Cypress component test). (As an aside, I want to note that my preference/vote on this is based on EUI's role as a component library - for a fully-fledged app/solution, I would recommend E2E tests instead as basic smoke/regression tests and not necessarily for edge cases). Oh, and BTW - I've had to write Cypress docs a few separate times for Enterprise Search (😅) and would be happy to donate some of the debugging tips I've already written. (It's not plagiarizing if you're stealing from yourself, right?) |
|
Oh, one more possible consideration - something to keep an eye on with Cypress/E2E tests is the amount of time tests will take to run in CI. Currently EUI CI seem super fast per PR (are they running all jest tests? I haven't actually checked 🙈) and adding a few Cypress tests here or there probably won't add to that significantly to start. It ramps up pretty quickly though and I could see CI starting to take 30min+ if (for example) every single component had its own Cypress test. TBF my barometer for CI times is way off since I got used to Kibana's 2hr+ runs, and EntSearch also similarly used to take around 30 mins as well, so that's definitely not the worst thing in the world - just something to keep in mind and maybe re-evaluate goal-wise if we start running into long CI times. |
Motion [to not do this] carried!
Motion [to not do this] carried!
+++
🎉 yes please - let's add a new .md file with this PR in wiki with any helpful cypress thoughts
Absolutely, thanks for calling it out! I feel our CI time is already on the long end and tidying that up has been on my personal backlog; there's probably a decent amount of cleanup/optimization with the webpack config to speed this up too |
Sweet! Is this something you'd like me to contribute now, or wait until you're more done tweaking Cypress config/setup etc. first? |
Contributing into this PR would be great 👍 |
+ update a few current testing docs to point to new Cypress doc
|
👋 I added a start at Cypress documentation! Some of it I yolo-guessed at so definitely feel free to fix/update anything I was way off-base about. The debugging section has 2 sets of TODOs around where we store failure screenshots locally and on CI - if we're not running Cypress on CI just yet feel free to delete that section |
|
Docker container works 🎉 Unfortunately another build step is still on the wrong node version, looking at that next |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5042/ |
This comment has been minimized.
This comment has been minimized.
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5042/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5042/ |
cee-chen
left a comment
There was a problem hiding this comment.
Looking and working great for me locally! Wahoo!! 🚀 🚀 🚀
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_5042/ |
* Added Cypress and added an example e2e integration test for EuiFocusTrap as well as a component test example for the same * cypress.json * Removed some default cypress files, cleaned up the related configurations * converting cypress spec to typescript but have some issues * Add documentation + update a few current testing docs to point to new Cypress doc * newline nit * bump node version, update docker image * It is nice to run the things you meant to run * set a specific OS for CI jobs * Use modern node version in the deploy docs CI job * Use the CI docker image in the build_docs job too * PR feedback Co-authored-by: Constance Chen <[email protected]> Co-authored-by: Constance <[email protected]>
Why
Some things are incredibly hard to write jest tests for, especially focus management or other low-level browser things.
.innerTextvs.innerContentis another good example, which we deal with in inner_text.tsx and account for via interesting ways in that component's unit tests.Questions/Explorations
Visual regression testingmaybe in the futureDo we want integration testing?no / not yetWeren't you opening this as a discussion?Yes but then I opted for a PR so it includes the difftestyarn script which runs in CI, we'll see if jenkins falls over or notCypress links
Support landing page
Overview, guides
API docs
FAQ
Use, how to run
component test
yran test-cypressto run component tests headless (no window appears)yarn test-cypress-devlaunches a chrome window controlled by cypress, which lists out the discovered tests (only focus_test.spec.js at the moment) and allows executing/interacting from that window.Changes
externals, which are only useful for thedistbundle/build anyway (a quick stop-gap to get this running)testyarn scriptChecklist
- [ ] Check against all themes for compatibility in both light and dark modes- [ ] Checked in mobile- [ ] Checked in Chrome, Safari, Edge, and Firefox- [ ] Props have proper autodocs and playground toggles- [ ] Checked Code Sandbox works for the any docs examples- [ ] Checked for accessibility including keyboard-only and screenreader modes- [ ] A changelog entry exists and is marked appropriately