chromaui / chromatic-e2e

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

Put Cypress archives in temp directory #38

Closed skitterm closed 8 months ago

skitterm commented 8 months ago

Issue: #AP-3824

What Changed

Writes archives to the Cypress-managed /cypress/downloads folder instead of the project root (the /cypress/downloads folder is cleared by Cypress at the beginning of each test run). This makes sure we have correct assets and that we don't bleed assets over between test runs (e.g. if you had a spec, ran a test, then removed that spec and ran the test again, we'd expect there to not be a story entry or spec-specific assets from that removed spec).

This doesn't handle if the user has configured a custom download folder; I'll make a ticket to handle that in the future.

2 situations where /cypress/downloads folder is not cleared before a test run:

  1. Cypress in interactive mode (e.g. npx cypress open)
  2. User configures trashAssetsBeforeRun to false

Alternatives I considered

I originally planned on managing the archives directory ourselves -- clearing it out before each test run via the before:run lifecycle hook. However, this has a couple downsides:

  1. The user would have an extra import of ours to put in their cypress.config.js file (since we shouldn't just create all lifecycle event listeners for them)
  2. This also doesn't run in Interactive mode

I figured we might as well use the Cypress-managed directory like we do for Playwright.

How to test

  1. Set up a Cypress project that uses Chromatic e2e
  2. Run a spec with `npx cypress run --spec path/to/spec
  3. Verify that the /cypress/downloads/ folder contains the chromatic-archives/ directory
  4. Run npm run archive-storybook
  5. Verify that the story has the correct assets
  6. Add some random file to the /downloads directory
  7. Run npx cypress run --spec path/to/spec again
  8. Verify that the random file is blown away

Change Type

thafryer commented 8 months ago

:rocket: PR was released in v0.0.40 :rocket: