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

Add visual regression testing with cypress #1339

Closed
wants to merge 2 commits into from

Conversation

raimund-schluessler
Copy link
Contributor

@raimund-schluessler raimund-schluessler commented Aug 23, 2020

This PR tries to add visual regression testing with cypress. I think we really need this, since some components start to be that complex, that we cannot change them without automatically testing for visual regressions. E.g. the AppSidebar component has at least 64 valid combinations of props and slots only for the header, which all change the visual appearance of the component. Testing this manually is basically impossible, since every small change needs to be tested with every valid combination of options. So visual regression testing would help a lot to resolve #1338 and prevent similar problems in the future.

However, the cypress setup does not work at the moment, I get the multiple similar errors like this: Fixed with a90e2b4

Error: Webpack Compilation Error
./src/components/AppSidebar/AppSidebar.vue?vue&type=style&index=0&id=4a2a5f2f&lang=scss&scoped=true& (./node_modules/css-loader/dist/cjs.js!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/resolve-url-loader!./node_modules/sass-loader/dist/cjs.js??ref--1-3!./node_modules/vue-loader/lib??vue-loader-options!./src/components/AppSidebar/AppSidebar.vue?vue&type=style&index=0&id=4a2a5f2f&lang=scss&scoped=true&)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (80)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.14.1
 @ ./src/components/AppSidebar/AppSidebar.vue?vue&type=style&index=0&id=4a2a5f2f&lang=scss&scoped=true& (./node_modules/vue-style-loader!./node_modules/css-loader/dist/cjs.js!./node_modules/vue-loader/lib/loaders/stylePostLoader.js!./node_modules/resolve-url-loader!./node_modules/sass-loader/dist/cjs.js??ref--1-3!./node_modules/vue-loader/lib??vue-loader-options!./src/components/AppSidebar/AppSidebar.vue?vue&type=style&index=0&id=4a2a5f2f&lang=scss&scoped=true&) 4:14-382
 @ ./src/components/AppSidebar/AppSidebar.vue?vue&type=style&index=0&id=4a2a5f2f&lang=scss&scoped=true&
 @ ./src/components/AppSidebar/AppSidebar.vue
 @ ./tests/visual/components/AppSidebar/AppSidebar.spec.js
 @ multi ./tests/visual/components/AppSidebar/AppSidebar.spec.js

Now I get

Running:  AppSidebar/AppSidebar.spec.js                                                   (1 of 1)


  1) An uncaught error was detected outside of a test

  0 passing (862ms)
  1 failing

  1) An uncaught error was detected outside of a test:
     ReferenceError: The following error originated from your test code, not from Cypress.

  > require is not defined

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Will look into this tomorrow.

Any feedback is very welcome, since I am new to cypress. @skjnldsv I saw that you use cypress for the viewer app, maybe you have an idea what is wrong here.

@raimund-schluessler raimund-schluessler added enhancement New feature or request help wanted Extra attention is needed 2. developing Work in progress high High priority design Design, UX, interface and interaction design labels Aug 23, 2020
cypress.json Outdated Show resolved Hide resolved
cypress/start.sh Outdated Show resolved Hide resolved
cypress/stop.sh Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@skjnldsv

This comment has been minimized.

@juliusknorr

This comment has been minimized.

@raimund-schluessler

This comment has been minimized.

@skjnldsv

This comment has been minimized.

@raimund-schluessler

This comment has been minimized.

@raimund-schluessler

This comment has been minimized.

@raimund-schluessler

This comment has been minimized.

@raimund-schluessler
Copy link
Contributor Author

raimund-schluessler commented Aug 24, 2020

I think it basically works now. This is the screentshot cypress produces on my system for a simple AppSidebar:

AppSidebar vue -- Renders snap

Things to do:

  • Fix jest to not run the visual tests
  • Take screenshots for all valid sidebar options (with and without figure, with and without star, with and without actions, etc. and all combinations)
  • Cleanup

@skjnldsv
Copy link
Contributor

Awesome work @raimund-schluessler 🤗

@raimund-schluessler
Copy link
Contributor Author

raimund-schluessler commented Aug 24, 2020

I added a visual regression test for 24 combinations of figure, secondary-actions, starred and compact. Here is an example image with all options so far:

AppSidebar.vue - starred_true - compact_true - header_image - secondary_button:
AppSidebar vue - starred_true - compact_true - header_image - secondary_button snap

Please have a look at them in cypress\snapshots\AppSidebar\AppSidebar.spec.js. So far I think they look good, but I haven't tested with long title and subtitle, without subtitle, with primary-actions and in editable mode. So I guess there are more combinations to come 🙈

Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

  • Please add cypress/videos to gitignore :)
  • Maybe also play with the background instead of the header?
  • Shall we add a default SdidebarContent?
    • If not maybe we can only capture the header?
  • Add Cypress action

@raimund-schluessler
Copy link
Contributor Author

Looks like we have to run cypress in a Docker container as the images produced by the Github action differ from the ones on my machine. @skjnldsv Do you have an idea how to do that?

@skjnldsv skjnldsv force-pushed the feature/vrt-cypress branch from 02dc3c5 to 13234dd Compare August 25, 2020 16:14
@skjnldsv
Copy link
Contributor

Mind pushing your adjusted branch to the repo? Then I would play around with it a bit.

DOne, sorry! :)

@raimund-schluessler
Copy link
Contributor Author

Seems to work with another plugin that seems supported

Hum, not really. mjhea0/cypress-visual-regression#50 :(

Hm, no idea. I get the same error no matter what.

@skjnldsv skjnldsv force-pushed the feature/vrt-cypress branch from 13234dd to 3860779 Compare August 25, 2020 18:23
@skjnldsv
Copy link
Contributor

Fixed @raimund-schluessler
The strings contained new lines :)

@skjnldsv skjnldsv added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 25, 2020
@raimund-schluessler
Copy link
Contributor Author

Nice, it runs through on my machine now. But the screenshots taken are different from the previous ones. I will try to update them and push them here. Let's see.

@skjnldsv
Copy link
Contributor

Nice, it runs through on my machine now. But the screenshots taken are different from the previous ones. I will try to update them and push them here. Let's see.

The screenshots seems to actually be the same :)
It currently fails because there is a tiny diff

The "AppSidebar.vue - starred_null - compact_false - header_none - secondary_button" image is different. Threshold limit exceeded! 
Expected: 0 
Actual: 0.13896919372599592

@raimund-schluessler
Copy link
Contributor Author

Nice, it runs through on my machine now. But the screenshots taken are different from the previous ones. I will try to update them and push them here. Let's see.

The screenshots seems to actually be the same :)
It currently fails because there is a tiny diff

The "AppSidebar.vue - starred_null - compact_false - header_none - secondary_button" image is different. Threshold limit exceeded! 
Expected: 0 
Actual: 0.13896919372599592

That's what I meant with "different". The letters are rendered slightly different than before.

@skjnldsv
Copy link
Contributor

skjnldsv commented Aug 25, 2020

It seems it's not uploading the diff files though
Some example on how to upload the artifacts:

cypress-io/github-action@22681e3

EDIT: doesn't upload to cypress but to github 😕
Maybe it's because I added this to gitignore 🤔

EDIT2: nope! 😢

@skjnldsv
Copy link
Contributor

We could also use https://github.com/meinaart/cypress-plugin-snapshots
Now that we have it working and we understand it better.
It seems up to date compared to https://github.com/palmerhq/cypress-image-snapshot

@raimund-schluessler
Copy link
Contributor Author

We could also use https://github.com/meinaart/cypress-plugin-snapshots
Now that we have it working and we understand it better.
It seems up to date compared to https://github.com/palmerhq/cypress-image-snapshot

I don't mind. Both https://github.com/mjhea0/cypress-visual-regression and https://github.com/meinaart/cypress-plugin-snapshots seem to be fine.

The question is how to handle the small differences in the screenshots. Whether we can prevent the different rendering or increase the threshold.

@raimund-schluessler
Copy link
Contributor Author

raimund-schluessler commented Aug 25, 2020

@skjnldsv I think it uploaded correctly: https://dashboard.cypress.io/projects/3paxvy/runs/8/test-results/408ee0df-0b7a-41b3-b473-433ba35020af

How we treat slightly different screenshots is still up to debate.

@skjnldsv
Copy link
Contributor

@skjnldsv I think it uploaded correctly: dashboard.cypress.io/projects/3paxvy/runs/8/test-results/408ee0df-0b7a-41b3-b473-433ba35020af

It's missing the superposée red diffs images :)

@raimund-schluessler raimund-schluessler force-pushed the feature/vrt-cypress branch 2 times, most recently from a46be18 to 1e7d85e Compare August 26, 2020 16:30
@raimund-schluessler
Copy link
Contributor Author

raimund-schluessler commented Aug 26, 2020

@skjnldsv I moved the cypress runner into a docker container 1e7d85e. This ensures that the local results and the results in CI are exactly the same, since they run in the samer docker container.

Now we only need to fix the uploading to cypress.io and cleanup a bit.

  • Move docker files to cypress folder if possible Seems difficult
  • De-duplicate github cypress actions
  • Fix uploading to cypress.io (not really necessary but nice to have)

@raimund-schluessler raimund-schluessler force-pushed the feature/vrt-cypress branch 2 times, most recently from f093d49 to 1ca40a6 Compare August 26, 2020 20:17
@raimund-schluessler
Copy link
Contributor Author

raimund-schluessler commented Aug 26, 2020

@skjnldsv Please have a look. I think it is in a good shape now.

I would add more conditions for AppSidebar (primary-actions, long title etc.) in a follow-up PR, so we can also test if it really finds regressions.

By the way: changing something on the AppSidebar CSS is correctly reported. 👍

Achieves reliable results cross-platform

Signed-off-by: Raimund Schlüßler <[email protected]>
Comment on lines +32 to +35
- name: Cypress run
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
run: npm run cypress:record
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fond, I think that complicates the setup a lot.
Why did we need to load this inside a docker container?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why did we need to load this inside a docker container?

Because the tests now pass, and failed before 😉

The tiny differences we saw with the font rendering are caused by running the tests on different machines. Between them, maybe the browser, the display settings, the available fonts or whatever else differs slightly, leading to tiny differences in the rendering which make the tests fail.

Of course, we could increase the difference threshold to make the tests pass. But this is not really an option as it would lead to false positives.

The difference in this image is 0.1623 and is not a regression (it's the difference between running locally on my machine and inside the docker container):
AppSidebar vue - starred_null - compact_false - header_none - secondary_none-diff

The difference in this image is 4 times lower with 0.0406 and it clearly is a regression (I intentionally changed the padding of the close button):
AppSidebar vue - starred_null - compact_false - header_none - secondary_none-diff

So, running the visual tests in the very same environment ensured by a docker container seems like the only option to fix this. If you have another idea, I am open to check it out.

I think that complicates the setup a lot.

It sure is complicated, but I got the impression, so is visual regression testing in general 🙈

Copy link
Contributor

Choose a reason for hiding this comment

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

Cypress actually have dockerized github actions as well.
We could have use those?

I'm just not fond of having to also maintain a Docker setup there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am fine with using this github action docker setup, but we have to as well locally run cypress within the container. How would you do that then?

matrix:
node-version: ['12.x']

name: Runner ${{ matrix.containers }}
Copy link
Contributor

Choose a reason for hiding this comment

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

No parallelism anymore (Wasn't needed because we have 1 test, but how would we add more?)

Copy link
Contributor Author

@raimund-schluessler raimund-schluessler Aug 27, 2020

Choose a reason for hiding this comment

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

I don't think we gain much here. The whole Cypress action runs for 4:00 min. The cypress run took 35 s, of which running the actual AppSideber.visual.js test took 10 s. We would need to add a lot of tests to really save time.

Edit: But feel free to add it again, of course.

@raimund-schluessler raimund-schluessler deleted the feature/vrt-cypress branch April 7, 2021 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews design Design, UX, interface and interaction design enhancement New feature or request help wanted Extra attention is needed high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants