I'm using Jest to make integration tests for my serverless framework service. Currently I have .env files specifying the environment variables and there is where I have my problem.
In my package.json i have :
...
"scripts": {
...
"start": "npx sls offline start --env local --httpPort xxxx --port xxxx --lambdaPort xxxx"
}
...
When I call yarn start the service starts correctly reading from .env.local file. But when I call exec('yarn start') inside the beforeAll function (because I need to run the service to test the endpoints) the service starts with the configuration from the .env file and not .env.local.
I ran out of ideas of how to set the right variables, I have used jest setupFiles and tried to set the variable manually like process.env.ENV1='XX' but it did not work. Until now the only thing that worked out was to change my test script from jest to ENV1=X ENV2=Y ENV3=Z jest but it does not feel right.