Docs: Set NODE_ENV
to test
for Accurate Environment Variable Loading with Cypress
#54263
Labels
NODE_ENV
to test
for Accurate Environment Variable Loading with Cypress
#54263
What is the improvement or update you wish to see?
I would like to address an inaccuracy in the docs with regards to testing Next.js (as a user of a Next.js app).
The Next.js docs state:
At least with regards to Cypress, the user must opt-in to the testing environment. I am open to playing around with Jest, though I suspect based on their docs that again the user will need to opt next.js into the testing environment.
In other words, to test a Next.js app with Cypress, I believe it is a better pattern to run
NODE_ENV=test next dev
to leverage Next.js'sNODE_ENV
-sensitive environmental variable load orderIs there any context that might help us understand?
I threw up a quick proof of concept demonstrating that the
package.json
script must specify theNODE_ENV
when starting the Next.js process in order to access.env.test
. (Note: this project was initialized withnpx create-next-app --example with-cypress with-cypress-app
)The key takeaway is that reverting phil-loops@19edb21 causes the cypress tests to fail, since the changed test is expecting the value from
.env.test
. Only by explicitly telling Next.js that we want to start in the test environment can the test pass.Does the docs page already exist? Please link to it.
https://github.com/vercel/next.js/tree/canary/examples/with-cypress
The text was updated successfully, but these errors were encountered: