-
Notifications
You must be signed in to change notification settings - Fork 65
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
different defaults for test and development #130
Comments
That's correct, |
Yes, that's an option. But then I don't understand why we need devDefault since we can control dev environment too. Currently I use a helper similar to testOnly, but it accepts two values: one for test and one for dev as a fallback. Maybe this version of testOnly where you can specify a fallback would be a bit more comfortable? What do you think? |
I second request for cleanEnv(
inputEnv,
{
LOG_LEVEL: str<LevelWithSilent>({
default: 'info',
testDefault: 'silent',
choices: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],
}),
}
); I can take time to implement that if necessary. |
if (rawValue === undefined) {
// Use devDefault values only if NODE_ENV was explicitly set, and isn't 'production'
var usingDevDefault = rawNodeEnv && rawNodeEnv !== 'production' && spec.hasOwnProperty('devDefault'); it's because of this condition in getSanitizedEnv |
I end up just using class-transformer because I already have it in my nestjs project @Expose()
@IsString()
@Transform(({ value }) => process.env.NODE_ENV === 'test' ? 'postgresql://testuser:testpassword@localhost:7000/testdb' : value)
DATABASE_URL!: string; function loadConfig() {
const config = plainToInstance(EnvironmentConfig, process.env, { enableImplicitConversion: true, strategy: 'excludeAll' });
const errors = validateSync(config, { skipMissingProperties: false });
if (errors.length > 0) {
throw new Error(`Configuration validation error: ${errors}`);
}
return config;
}
export const ENV = loadConfig(); |
Hi, bringing up the similar question to #32
The problem I'm trying to solve is to use different URI for mongo in tests because I'm dropping the entire collection after each test.
So what I want to achieve is something like that:
ENV_MONGO_URI: str({ devDefault: 'mongodb://mongo:27017/app', testDefault: 'mongodb://mongo:27017/app-test' })
If I understand correctly I can't use testOnly for that case since in development my uri will be undefined.
Thanks in advance!
The text was updated successfully, but these errors were encountered: