-
Notifications
You must be signed in to change notification settings - Fork 0
Technical design discussion #1
Comments
I thought I'd mention here as well that I won't be working actively on this for a while. I'm taking some time off in July and we'll mostly be doing support and maintenance in the coming month. I'll make sure to keep up-to-date with this thread though! |
This all sounds good to me :) |
This sounds ideal for CI - and is a solid place to start.
Is the server code OSS? I'd assumed it isn't in order to protect happo's service model.
This sounds potentially challenging, since presumably If we can get this right, |
Yeah, it's not.
It does if you have [the Happo GitHub app}(https://github.com/apps/happo) installed and connected your github repo. We store a simple
Yeah this would be fantastic! I think with the power of Jest and a smart way to put together the happo.io integration, we could get there. One thing we'll have to be smart about is performance. Waiting for a screenshot for each Here's how a test result could look like:
I don't know enough about controlling the Jest output to tell if this output is even possible though. :) |
Is the idea here for making a jest runner that runs all of the Happo tests (e.g. like jest-runner-eslint for running ESLint), or is this for adding Happo tests to existing jest runs? |
Good question @lencioni -- I don't know to be honest. Ideally you'd be able to mix in some happo screenshots with your regular tests, but I don't know if that's feasible. I do think that we should allow people to write jest tests just like they're used to (with |
jest-playwright might be worth a look: https://github.com/playwright-community/jest-playwright |
We started a discussion around this module on Twitter and I wanted to summarize a few things and outline my thoughts on how this library could work, and then we can collaborate on the design in this issue.
https://twitter.com/CraigCav/status/1278100205779419137?s=20
Background
This project started when @emilsjolander reached out to me asking to run Happo via Jest. I had previously made attempts that failed for various reasons (mostly related to getting styles and images/assets working with Jest). I started a new attempt and found that some of the earlier headaches were mostly gone. Jest now has all the hooks and events that we need and I think we could make a really good Happo runner with the help of it.
Usage in CI
So far, I've mostly been concerned with getting this library to work in a CI workflow. That means generating screenshots and comparing them with a previous version (baseline). Other Happo integrations (Happo Examples, Storybook, Cypress all work in similar ways:
My idea for the Jest integration is to make the test runner quite "dumb" -- it will simply take screenshots (remotely via the Happo API). Comparing screenshots with previous versions will be handled separately, just like the happo-cypress integration does.
Dev usage
Jest is excellent at rapid local development. You start up in watch mode and can change code around until the tests pass. It would be great if the happo integration could make use of this as well, and help make local development smooth. Ideally it would
For that last item, we'd likely need to make some changes on the server. We can use the compare reports endpoint and pass in a known
sha1
from the master branch, plus the (currently undocumentedisAsync
param, see happo-cypress for usage. If Happo has a report forsha1
, it will compare against it. If no report is found, Happo will traverse the git history to find a report that we can compare with.Recording HTML + CSS and collecting assets
The actual screenshooting happens on Happo's workers (different ones per browser target). We need something in Jest that simply snapshots the DOM. E.g.
When those
screenshot
calls are made, we need to collect the HTML, the CSS and any assets currently rendered. This is basically what happo-cypress does 1, 2, 3, and it's possible we could extract some generic DOM snapshot library that we could use in both places (although I'm fine keeping things separated/duplicated to begin with).Generating screenshots remotely
Then with all those snapshots collected, we can send them to happo.io for remote screenshooting. For that, we use the
snap-requests
API endpoint (undocumented!), via theRemoteBrowserTarget
class. See happo-cypress for an example of how we send these payloads. I think we can do this in a customHappoEnvironment
for jest, in the teardown method.We also have to put all those snap-requests together in a Happo report. This will "finalize" the full run and give us something to run comparisons with. I'm not 100% sure where this code goes. In happo-cypress, it's in two places: in an after hook when running locally and in a wrapping command when running in CI.
Comparing reports and generating diffs
When we have a baseline sha and a report that we just created, we can run a comparison between the two. In happo-cypress, this happens in a wrapping command (which was the only way to get some code to run after the entire test suite). We need to do something similar in happo-jest. Resolving the baseline and some other useful env variables happens in a
resolveEnvironment
module for happo-cypress and we should be able to do the same. It knows things about different CI environment.Notes
The reason I'm referencing the happo-cypress project and not the
happo.io
library is that we've decided to move away from a few things we did wrong in the happo.io library:happo-ci
)The text was updated successfully, but these errors were encountered: