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

Issue with envalid in test. #216

Open
Darkmift opened this issue Dec 14, 2023 · 1 comment
Open

Issue with envalid in test. #216

Darkmift opened this issue Dec 14, 2023 · 1 comment

Comments

@Darkmift
Copy link

Darkmift commented Dec 14, 2023

I need someone to please explain why I need "message" and "stack" here:

import { cleanEnv, makeValidator, str, testOnly } from 'envalid';
import logger from '../utils/logger-winston';

const env = cleanEnv(
    process.env,
    {
        MONDAY_API_KEY: str({ devDefault: testOnly('') }),
        NODE_ENV: str({ choices: ['development', 'production', 'test'] }),
        message: str(),
        stack: str(),
    },
    {
        reporter: (data) => {
            logger.info(`There are errors in the environment variables:`, { data });
        },
    },
);

export default env;

without these vars

2023-12-14 17:46:04 [info]: There are errors in the environment variables:
{
  "data": {
    "errors": {},
    "env": {
      "MONDAY_API_KEY": "***",
      "NODE_ENV": "test"
    }
  },
  "level": "info",
  "message": "There are errors in the environment variables:",
  "timestamp": "2023-12-14 17:46:04"
}

with said vars:

2023-12-14 17:48:31 [info]: There are errors in the environment variables:
{
  "data": {
    "errors": {
      "message": {
        "name": "EnvMissingError"
      },
      "stack": {
        "name": "EnvMissingError"
      }
    },
    "env": {
      "MONDAY_API_KEY": "***",
      "NODE_ENV": "test"
    }
  },
  "level": "info",
  "message": "There are errors in the environment variables:",
  "timestamp": "2023-12-14 17:48:31"
}
@hacmak18
Copy link

Hey @Darkmift
In which version you are facing this? it's working fine for me in 7.2.2

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