chromaui / chromatic-e2e

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

Cypress: Detecting interactive mode, take 2 #78

Closed skitterm closed 5 months ago

skitterm commented 5 months ago

Issue: #AP-4060

What Changed

Differentiates between Cypress' "run mode" (used for CI) and "interactive mode" (used for interactively clicking through tests and seeing the DOM), via config.isTextTerminal. This is so we don't need users to prepend their cypress open command with the ELECTRON_EXTRA_LAUNCH_ARGS env variable, and also makes it so we won't archive in interactive mode.

Previously I had tried doing this through config.isInteractive in #72, but due to a Cypress bug that value wasn't getting the correct values in all cases.

Note that config.isTextTerminal is undocumented. However, it's the way users in the bug ticket recommended to do, and more importantly, it's how Cypress appears to be telling things whether to be in "run mode" or "interactive mode" in their tests, so we should be pretty safe.

API Change

This requires Cypress users to now pass config to installPlugin, as follows:

// cypress.config.ts|js file
export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // previously was just `installPlugin(on)`
      installPlugin(on, config);
    },
  },
});

How to test

Cypress run command:

Chromatic build:

Cypress, interactive mode: