2
votes

Cypress is by default run in production mode (process.env.NODE_ENV === 'production'). I want to run it in 'test' mode because I have some functionalities in my code which should not be run under test, for example reporting to Sentry

I have something like this in my application code:

if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'development') {
//report to sentry
}

I have tried to set environment variables in Cypress but it is set only for test files.

"test:e2e": "percy exec -- vue-cli-service test:e2e --mode test"

I have also tried to run command with --mode test but then there is a problem with test runner (is not starting tests)

Regards

1
Isn't it your app that needs to run in test mode?Mikkel
Cypress does not compile your app. It just opens an URL. So either you provide cypress an URL with an app that runs per default in TEST mode or you control it by adding a request header that is parsed in your app or someething like that.Josef Biehler

1 Answers

2
votes

You are passing an option to cypress and not setting an environment variable. If you want to set an environment variable do this on mac,

"test:e2e": "NODE_ENV='development' percy exec -- vue-cli-service test:e2e"

or in windows

"test:e2e": "SET NODE_ENV='development'  percy exec -- vue-cli-service test:e2e"

or you can use something more sophisticated like this https://www.npmjs.com/package/cross-env