Giter VIP home page Giter VIP logo

Comments (5)

meredian avatar meredian commented on May 17, 2024 3

I second request for testOnly. Since NODE_ENV=test is first-class citizen (there's isTest), I think it worth having ability to have different defaults for dev & test will make things more consistent. Things behave somewhat different for "dev" (real service start for local development or staging environments) and "test" (run automated tests, units and integration, does not launch some global components). Simplest practical usecase is e.g logging, which is supressed by default in test, but not in dev.

 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.

from envalid.

misha-erm avatar misha-erm commented on May 17, 2024 2

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?

from envalid.

af avatar af commented on May 17, 2024

That's correct, testOnly('foo') will only use 'foo' as a default value when NODE_ENV is test. Since you probably can control your test environment, why not just add ENV_MONGO_URI=... as part of your testing command?

from envalid.

DenisVASI9 avatar DenisVASI9 commented on May 17, 2024
 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

from envalid.

DenisVASI9 avatar DenisVASI9 commented on May 17, 2024

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();

from envalid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.