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

WIP: src/components/__tests__: use snapshot test for testing icon rendering #456

Open
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

maceksimon
Copy link
Contributor

Add a common test command testIcon that makes use of snapshot command to visually test rendered icon.
Replace individual icon tests with the common test across component test specs.

@tmszi
Copy link
Member

tmszi commented Jun 25, 2024

My opinion that tests are failed (number of image pixels are different) under Mozilla Firefox web browser, because that scrollbar width size is different across web browsers and rendered image size will be different (I solved similar issue in the past). Solution is disable scrollbar before running tests (I think we have this example in our test code).

@tmszi
Copy link
Member

tmszi commented Jul 2, 2024

With git reset --hard 2e155ff699ede420aadc8178dfa78153251ebbe0 and interactively tested BannerChallengeDescription.cy.js component test I got this message:

wrap<i.q-icon.notranslate.material-icons>
26
taskMatching image snapshot, Object{3}
(uncaught exception)CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise. The command that returned the promise was: > cy.task() The cy command you invoked inside the promise was: > cy.log() Because Cypress commands are already promise-like, you don't need to wrap them or return your own promise. Cypress will resolve your command with whatever the final Cypress command yields. The reason this is an error instead of a warning is because Cypress internally queues commands serially whereas Promises execute as soon as they are invoked. Attempting to reconcile this would prevent Cypress from ever resolving.

Make code simple as possible, please.

@tmszi
Copy link
Member

tmszi commented Jul 2, 2024

BannerChallengeDescription.cy.js component test (icon image snapshot) passed across different web browsers.

Refactored and simplified testIcon cy command func with increased timeout to 4 seconds.

Cypress.Commands.add('testIcon', ({ element, name }) => {
  cy.get(element[0]).matchImageSnapshot(name, {
    failureThreshold: 0.1,
    failureThresholdType: 'percent',
    timeout: 4000,
    customDiffConfig: { threshold: 0.4 },
    screenshotsFolder: 'test/cypress/snapshots',
    retries: 2,
  });
});

Which tests you are identify as the problematic tests?

@maceksimon maceksimon force-pushed the feature/icon-test branch from c130bc8 to 927350d Compare July 2, 2024 20:37
@maceksimon
Copy link
Contributor Author

Updated with the simplified example.
Letting the tests re-run.
Currently, on local tests, I get error from ListCardProgress and SliderProgress. Both are related to malformed snapshot files, returning:
TypeError: The "target" argument must be an instance of Buffer or Uint8Array. Received null

@tmszi tmszi force-pushed the feature/icon-test branch from e77a568 to ebf70b5 Compare July 17, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants