-
Notifications
You must be signed in to change notification settings - Fork 157
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
Tests do not load .env or serverless.yml variables #51
Comments
Oh good catch. Yeah I'll have a look at how to do this in the serverless-bundle plugin. |
@jayair Any update on this issue? |
Yeah I just pushed a beta version. Give it a try! |
Environment variables are working for me in tests, but the sample docs are a bit confusing. In the sample
with the following in the
This leads to a mismatched environment between the code and the tests. In the code, the given environment variable is accessed under To avoid this confusion, I think the samples should be changed to be consistent also. The sample variable should either be Hope this makes sense... :) |
@jeff-kilbride Good catch, let me update the sample in the comment. |
looks good to me |
I'm coming across an issue using the same three serverless plugins as serverless-nodejs-starter. My project uses env vars defined in the serverless.yml based on custom serverless variables, like so:
Ideally, 'serverless-bundle test' would use env vars defined in serverless.yml instead of the .env file itself. Thanks for any ideas - could be missing something basic here. |
Hmm it doesn't right now. That's because the .env file is treated as the environment variables of the execution context, while the ones in the serverless.yml are the ones that are set in the Lambda function when it's deployed. It's actually a little tricky to do this because serverelss-bundle test is running the tests agains the bundled code and not against what Serverless Framework creates. |
On newest release when running
npm test
which runsserverless-bundle test
environment variables from serverless.ymlor from .env file
This issue was noticed in the serverless-bundle package and noted by @Vadorequest
AnomalyInnovations/serverless-bundle#4
Using his solution I was able to load .env variables by adding the following to the
package.json
jest-preload-env.js
severless-bundle test should load serverless.yml environment variables
The text was updated successfully, but these errors were encountered: