Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set NODE_ENV=test? #184

Open
stoplion opened this issue Jul 9, 2019 · 3 comments · May be fixed by #185
Open

How to set NODE_ENV=test? #184

stoplion opened this issue Jul 9, 2019 · 3 comments · May be fixed by #185

Comments

@stoplion
Copy link

stoplion commented Jul 9, 2019

{
"start-server-and-test": "^1.9.1",
}
OS X 10.13.6

I'm using start-server-and-test to run Cypress. We have a IP restriction when NOT in NODE_ENV=test. So, I run NODE_ENV=test start-server-and-test start http://localhost:5000 cy:open. But console.log(process.env.NODE_ENV) on the server shows it is still in development mode, so no tests ever run.

How can I set the NODE_ENV when using start-server-and-test?

@bahmutov
Copy link
Owner

bahmutov commented Jul 9, 2019

@stoplion can you look at PR #185 and see if this matches your situation - I am testing there with NODE_ENV=... variable and it is set in the server process correctly.

@george-norris-salesforce

Yea I tried it, still sets it to development

@Norfeldt
Copy link

@bahmutov I think I got a similar issue NOT able to set PERCY_TOKEN via package script

I have been trying really hard to set the PERCY_TOKEN on a local test run according the official guideline from percy and trigger it via yarn.

The guideline says:

$ PERCY_TOKEN=aaabbbcccdddeeefff PERCY_BRANCH=local npm test

My attempt right now looks like this:

package.json

...
"scripts": {
    "start": "react-scripts -r @cypress/instrument-cra start",
    "start:silent": "BROWSER=none yarn start",
    "start:server": "start-server-and-test start:silent http://localhost:3000",
    "build": "react-scripts build",
    "eject": "react-scripts eject",
    "envGenerateExample": "cat .env | sed 's/=.*/=/g' > .env.example",
    "jest:test": "react-scripts test --env=jest-environment-jsdom-sixteen",
    "cy:run": " 'yarn start:server './node_modules/.bin/cypress run'",
    "cy:open": "yarn start:server './node_modules/.bin/cypress open'",
    "cy:ci": "yarn start:server cy:chrome",
    "cy:chrome": "cypress run --browser chrome --record",
    "percy:exec": "yarn percy exec -- cypress run",
    "cy:percy": "yarn start:server percy:exec",
    "percy:local": "PERCY_TOKEN=$(grep 'PERCY_TOKEN.*' .env | sed 's/.*=//'); PERCY_BRANCH=local;",
    "cy:percy:local": "yarn percy:local; yarn start:server percy:exec"
  },
...
$ yarn cy:percy:local

Compiled successfully!

You can now view playground in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://192.168.1.163:3000

Note that the development build is not optimized.
To create a production build, use yarn build.

...

> [email protected] percy:exec /Users/norfeldt/Repos/playground
> yarn percy exec -- cypress run

warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ /Users/norfeldt/Repos/playground/node_modules/.bin/percy exec cypress run
 ›   Warning: Skipping visual tests. PERCY_TOKEN was not provided.
...

If you want to try it out on your own percy then you more than welcome to clone this branch:

https://github.com/Norfeldt/react-kitchen-sink/tree/local-percy

and set the .env tokens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants