Skip to content
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

AWS related environment values get replaced #63

Open
holylander opened this issue Aug 2, 2021 · 6 comments
Open

AWS related environment values get replaced #63

holylander opened this issue Aug 2, 2021 · 6 comments

Comments

@holylander
Copy link

holylander commented Aug 2, 2021

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.

@freshollie
Copy link
Owner

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

@holylander
Copy link
Author

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

@freshollie
Copy link
Owner

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
Copy link
Owner

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

@holylander
Copy link
Author

holylander commented Aug 3, 2021

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
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants