jest-dynalite icon indicating copy to clipboard operation
jest-dynalite copied to clipboard

AWS related environment values get replaced

Open holylander opened this issue 3 years ago • 6 comments

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.

imagen

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.

holylander avatar Aug 02 '21 15:08 holylander

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) {
 ...
}

freshollie avatar Aug 02 '21 21:08 freshollie

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... imagen 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

holylander avatar Aug 03 '21 10:08 holylander

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

freshollie avatar Aug 03 '21 10:08 freshollie

Not sure of the best solution. These variables need to be set or dynamodb complains if they are not set.

freshollie avatar Aug 03 '21 10:08 freshollie

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)

holylander avatar Aug 03 '21 10:08 holylander

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

didnt know either, thanks for sharing :)

holylander avatar Aug 03 '21 10:08 holylander