Tests do not load .env or serverless.yml variables
See original GitHub issueOn newest release when running npm test
which runs serverless-bundle test
environment variables from serverless.yml
provider:
name: aws
runtime: nodejs10.x
stage: dev
region: us-east-1
environment:
TEST: "value"
or from .env file
TEST=value
This issue was noticed in the serverless-bundle package and noted by @Vadorequest https://github.com/AnomalyInnovations/serverless-bundle/issues/4
Using his solution I was able to load .env variables by adding the following to the package.json
"jest": {
"setupFilesAfterEnv": [
"./jest-preload-env.js"
]
}
jest-preload-env.js
require('dotenv').config({
path: './.env'
});
if (process.env.NODE_ENV !== 'test') {
throw Error('Non-test environment');
}
severless-bundle test should load serverless.yml environment variables
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Resolution of environment variables
The framework loads variables from only one .env file (if stage-specific .env is found, default .env is not loaded); The framework does not...
Read more >How to get environment variables defined in serverless.yml ...
Make the tests exec sls invoke - this will work but would mean that the code cannot be debugged, I won't know the...
Read more >Serverless Environment Variables - A Comprehensive Guide
Environments Variables in serverless.yml vs Environment Variables in your Serverless functions. If Serverless vs. serverless was not ...
Read more >Load Secrets from .env
We are using the serverless-dotenv-plugin to load these as an environment variable when our Lambda function runs locally. This allows us to reference...
Read more >Manage Serverless Environment Variables Per Stage
Not only can you live test functions locally by simulating events, but you can ... How do we configure our serverless.yml to do...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@jeff-kilbride Good catch, let me update the sample in the comment.
Oh good catch. Yeah I’ll have a look at how to do this in the serverless-bundle plugin.