chromaui / chromatic-e2e

Archive end-to-end tests to be replayed in Storybook and Chromatic
MIT License
13 stars 4 forks source link

cy.get('@archive') inside interceptor yields returned value to current subject #35

Closed tsirlucas closed 2 months ago

tsirlucas commented 8 months ago

Describe the bug I see the cypress implementation has a interceptor which calls a few cypress commands when a request happens. It seems that when you do it, the command you called set the subject on global level. If the command happens with the right timing, it will replace the global subject right when actual test commands are running.

e.g.

cy.get(MY_SELECTOR_HERE).should('have.text', 'whatever')

when the interceptor calls cy.get('@archive'), it will replace the selector subject with the archive value. Meaning the assertion .should('have.text', 'whatever') will run against the archive value and will probably break.

To Reproduce

A little hard to reproduce as you depend on timing here... But if you have a few tests it should be enough

Expected behavior I would expect it not to happen

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Tried to debug it with some tests I have locally... It seems that any kind of command you call on interceptor will replace subject whille tests are running and break things.

Maybe you need to rely on Cypress.env(key, value) or some other strategy to store archives? Tested it locally and it seems to work

tsirlucas commented 8 months ago

Just wanted to say that if you're ok with the Cypress.env approach, I can open the PR if cypress is not priority for you guys ATM. I know its not even released oficcialy yet

skitterm commented 8 months ago

Hi @tsirlucas, you're correct that we haven't released Cypress officially yet, though I appreciate your feedback.

We're actually going to take a different approach to archiving resources (using Chrome Devtools Protocol instead of cy.intercept()), so let's hold off on the PR. But thanks for pointing this out

winkerVSbecks commented 2 months ago

Going to close this issue since, Chromatic went with an alternative approach.