cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.66k stars 3.16k forks source link

`isInteractive` always true in plugins #20789

Open badeball opened 2 years ago

badeball commented 2 years ago

Current behavior

The isInteractive properly appears to always be true in the eyes of plugins, despite when in run-mode.

Desired behavior

No response

Test code to reproduce

export default (
  on: Cypress.PluginEvents,
  config: Cypress.PluginConfigOptions
): Cypress.PluginConfigOptions
  config.isInteractive // always true
}

Cypress Version

9.5.2

Other

No response

emilyrohrbough commented 2 years ago

@badeball I see you also opened #https://github.com/cypress-io/cypress/issues/20789, are you utlizing this value to determine how your plugin should behave?

badeball commented 2 years ago

Exactly, yes. For my plugin, some configuration options are more sensible in run-mode compared to open-mode, so in absence of an explicit choice from the user I want my plugin to behave least surprising, which for my case mean differing between the two modes.

badeball commented 2 years ago

Maybe I've been unclear here, but

This is set by Cypress when open mode is leveraged and It's not intended to be a configurable property.

this value appears to be true when open mode is not leveraged as well.

badeball commented 2 years ago

And just to be thorough again, I don't intend to set this attribute, merely read it.

luxalpa commented 1 year ago

I'm having the same issue. I have a plugin that adds some utility stuff like a webserver and such for the user to interact with via the user interface (in my case it's about managing database snapshots and docker containers); I don't want this stuff to run in the run mode. I wonder why this would be broken and if it's relatively easy to fix?

ryanjduffy commented 1 year ago

@badeball, @luxalpa - Just ran into this and discovered that config.isTextTerminal does seem to be updated for plugins and can be used as a proxy for isInteractive. I found that cypress sets isInteractive as the opposite of isTextTerminal so perhaps that'll work for you.

burakbasbug commented 1 year ago

I can confirm the issue still exists on the version 12.9.0

marktnoonan commented 1 year ago

I've been able to reproduce this also, so I'm routing it to the team. Thanks for the report and follow up!

In the meantime, is config.isTextTerminal working as a workaround for people, or is this block for any of you?

Blocking or not, it's still clearly wrong though and should be corrected. It seems like plugin code might be needless running in run mode for some people.

AlexanderTunick commented 10 months ago

Reproducible for v13.2.0.

Currently took "config.isTextTerminal" as a temporary replacement until "isInteractive" flag is fixed

skitterm commented 7 months ago

This just bit me too (Cypress v13.6.2). My plugin listens to the network and archives the resources to the user's cypress/downloads folder. I'm using config.isInteractive (in the before:browser:launch event) to not do this during cypress open since the downloads folder isn't cleared in that case (and for a couple other reasons).

@jennifer-shehane in the meantime, is there a value I can reliably use to know whether the user is doing cypress open vs cypress run?

AlexanderTunick commented 3 months ago

This just bit me too (Cypress v13.6.2). My plugin listens to the network and archives the resources to the user's cypress/downloads folder. I'm using config.isInteractive (in the before:browser:launch event) to not do this during cypress open since the downloads folder isn't cleared in that case (and for a couple other reasons).

@jennifer-shehane in the meantime, is there a value I can reliably use to know whether the user is doing cypress open vs cypress run?

See my reply above for the temporary workaround. Works perfectly since Oct 2023.