-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Env variables not loaded for unit tests purpose #22936
Comments
Hi, Next.js isn't being invoked at all when running tests in the above set-up, you need to load the env manually with Closing as this doesn't appear to be a bug in Next.js and instead with the test set-up |
Hello @ijjk But that requires to make the build of NextJs before launching tests But, by having a look again on that topic #1790 and thanks to your help, I have been able to make working my unit test Below step to fix this issue
I would suggest to add this example in your doc, that could help all of us (as required by this (still opened) issue |
This adds a note to the environment variables documentation to mention how the env files can be loaded using the `@next/env` package as this has been brought up a few times. x-ref: #22936 (comment) x-ref: #17903
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
v10.0.9-canary.4
What version of Node.js are you using?
v14.16.0
What browser are you using?
Firefox
What operating system are you using?
Linux
How are you deploying your application?
no
Describe the Bug
If you set some environment variables in
.env
and.env.test
they are not taken into account while playing unit tests and tests based on these variables failExpected Behavior
With NextJs 10.0.6 it works well
To Reproduce
You can login to sandbox and play the unit tests set here https://codesandbox.io/s/laughing-leaf-zfp7k?file=/__tests__/testing-library.js
If you run
yarn test __tests__/testing-library.js
you will getundefined
instead offooBar
for the env variable set in.env.test
The text was updated successfully, but these errors were encountered: