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

testDefault? #32

Closed
novemberborn opened this issue Jun 13, 2017 · 7 comments
Closed

testDefault? #32

novemberborn opened this issue Jun 13, 2017 · 7 comments

Comments

@novemberborn
Copy link
Contributor

devDefault - A fallback value to use only when NODE_ENV is not 'production'. This is handy for env vars that are required for production environments, but optional for development and testing.

I'm using envalid in a server setup which needs to interact with AWS resources. I have a use case where a variable is required during development, but not during testing. I could set devDefault but that'll just lead to runtime errors. It'd be great if envalid could support a testDefault which only applies when NODE_ENV === 'test'.

@SimenB
Copy link
Collaborator

SimenB commented Jun 13, 2017

Interesting. Currently I manually pass args when calling envalid.cleanEnv. Is that not feasible?

@novemberborn
Copy link
Contributor Author

I've written a testOnly() method:

function testOnly (testDefault) {
  return process.env.NODE_ENV === 'test'
     ? testDefault
     : undefined
}

Which lets me do:

APP_COGNITO_CLIENT_ID: validators.cognitoUserPoolClientId({devDefault: testOnly('stub+client+id')}),

Which is an OK workaround, but having a testDefault property would be tidier.

@af
Copy link
Owner

af commented Jun 14, 2017

I like your workaround, and can't really think of a better one to be honest.

The issue I see with adding testDefault is that devDefault currently applies to both NODE_ENV=development and NODE_ENV=test, so IMO it'd be confusing if devDefault and testDefault overlapped. Also I'm not sure if test-only env vars are common enough to justify adding the feature– personally devDefault has always been sufficient for me.

Maybe we could add your testOnly helper function to the lib as a compromise?

@novemberborn
Copy link
Contributor Author

Fair enough.

You mean require('envalid').testOnly(value)?

@af
Copy link
Owner

af commented Jun 15, 2017

Yep, that's exactly what I'm thinking

@novemberborn
Copy link
Contributor Author

Cool, will keep this issue in mind. Have some other projects also hoping for my attention 😄

If anybody else wants to pick this up, feel free!

@af af closed this as completed in #36 Jun 16, 2017
af pushed a commit that referenced this issue Jun 16, 2017
barbogast pushed a commit to barbogast/envalid that referenced this issue Jun 16, 2017
@DenisVASI9
Copy link

How to use different values for test and for production?
I have an .env file created and the value is always from it

tuannm151 pushed a commit to BSSCommerce/shopify-envalid that referenced this issue Jul 1, 2024
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

4 participants