jest-dynalite
jest-dynalite copied to clipboard
AWS related environment values get replaced
I have a .env
file, with custom values for
AWS_ACCESS_KEY_ID = "somekey"
AWS_SECRET_ACCESS_KEY = "somevalue"
These values get replaced by the default values defined on https://github.com/freshollie/jest-dynalite/blob/master/src/setup.ts, no matter what I do.
Only when I have removed the preset: "jest-dynalite"
preset from the jest.config
file, my values remain as defined.
Do you know could be going wrong? thanks
PS: I would suggest to just remove those default values.
Very interesting.
Those values should only be placed if nothing is being set for those envs, so I can't understand why they are being overwritten.
if (!process.env.AWS_ACCESS_KEY_ID) {
...
}
yep its a bit odd.
I update the env variables following the dotenv
approach. This means, I have a .env.test
file, with a bunch of variables...
All of them are available just fine, however, the
preset: "jest-dynalite"
is replacing the values for AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
I ended in using a different name for storing such values, so they dont get replaced :-/, for instance, AWS_ACCESS_KEY_ID_VALUE
Dont you experience this issue as well? thanks
Ah. Looks like jest-dynalite
is setting these variables, and dotenv
won't overwrite variable which are already set (I didn't know this): https://github.com/motdotla/dotenv/blob/master/lib/main.js#L104
Not sure of the best solution. These variables need to be set or dynamodb
complains if they are not set.
I think It could be good to remove those defualt values.
They may be fine in most of the cases, however, you may have some integration or end2end test in which you really want to hit the aws dynamodb ( like I do : ), then, your tests will never work.
On the other hand, I think you will never be able to run this:
const client = new DynamoDB({
...yourConfig,
...(process.env.MOCK_DYNAMODB_ENDPOINT && {
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
sslEnabled: false,
region: "local",
}),
});
If you dont provide within yourConfig
object, some credential object thru new Credentials(AWS.accessKeyId, AWS.secretAccessKey)
Ah. Looks like
jest-dynalite
is setting these variables, anddotenv
won't overwrite variable which are already set (I didn't know this): https://github.com/motdotla/dotenv/blob/master/lib/main.js#L104
didnt know either, thanks for sharing :)