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

Image snapshot testing with Puppeteer #48

Closed
6 tasks done
rolyp opened this issue Mar 15, 2022 · 3 comments · Fixed by #53
Closed
6 tasks done

Image snapshot testing with Puppeteer #48

rolyp opened this issue Mar 15, 2022 · 3 comments · Fixed by #53
Assignees
Labels

Comments

@rolyp
Copy link
Contributor

rolyp commented Mar 15, 2022

Snapshot (approval) testing is useful for easy refactoring, and well supported by Jest. It's not quite trivial to set up for us because the map view renders asynchronously, and so waiting on "Nothing to show" doesn't seem to be enough for deterministic behaviour. The following diff illustrates different states that both satisfy expect(..).toContain("Nothing to show"):

image-name-diff

Maybe we can find a UI element to wait on that only appears when the map is fully loaded.

  • install jest-image-snapshot
  • import toMatchImageSnapshot from jest-image-snapshot and extend Jest’s expect API
  • condition that over-approximates map being fully loaded
    • waitUntil: "networkidle0" -- probably not very reliable
  • revisit snapshot tests in tgvejs (maybe no longer needed)
  • set visibility of map and loader component to hidden (to avoid problem with async map content)
  • change Puppeteer viewport size to include more of the side desk
  • export __snapshort folder as build artifact
  • set error tolerance in screenshot diffs to 0.5%

See:

@rolyp rolyp added this to the Meeting 2022-03-17 milestone Mar 15, 2022
@rolyp rolyp added the testing label Mar 15, 2022
@layik
Copy link
Collaborator

layik commented Mar 15, 2022

Shall we try waitUntil: 'networkidle2'?

@layik layik changed the title Snapshot testing with Puppeteer Image snapshot testing with Puppeteer Mar 15, 2022
@layik
Copy link
Collaborator

layik commented Mar 15, 2022

test1
test2
test3
These are captured with waitUntil: 'networkidle0', tried 2 almost identical.

@layik
Copy link
Collaborator

layik commented Mar 15, 2022

OK having played with many options on puppeteer, a solution which also contributes to overall tgvejs functionality is to generate the image snapshots without "basemap"s. This can be achieved by exporting another API called mapStyle and setting it to "No map". The results would be like. Please let me know @rolyp if you like me to send the commit (small one) to tgve/tgvejs.
test1
test3

Leave it here, got enough about puppeteer and how we are trying to use it. Great work btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants