Skip to content

feat: add testDefault spec attribute#249

Merged
af merged 1 commit into
af:mainfrom
garlab:feat/test-default
Jun 9, 2026
Merged

feat: add testDefault spec attribute#249
af merged 1 commit into
af:mainfrom
garlab:feat/test-default

Conversation

@garlab

@garlab garlab commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Add a testDefault spec attribute that takes priority when NODE_ENV == "test", addressing #130.

Comment thread README.md
### testOnly

The `testOnly` helper function is available for setting a default value for an env var only when `NODE_ENV=test`. It is recommended to use this function along with `devDefault`. For example:
The `testOnly` helper function is available for setting a default value for an env var only when `NODE_ENV=test`. It is used by wrapping a `devDefault` value:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (after this PR) it probably makes sense to just remove the testOnly helper– can you think of any remaining use for it? It's always been a bit awkward

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I don't see any remaining use cases for it. In fact I've been using envalid for more than 10 years (thanks for maintaining it!) and never used testOnly. I always wished there was a testDefault as my workflow is often to have no prod default but both dev & test defaults.

I would suggest to first release testDefault as a minor release and remove testOnly for the next major (I'm sure that's what you have in mind).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I just released v8.2.0, and v9 will follow in the next few days with testDefault removed and a few other small breaking changes

@af af merged commit cb67a44 into af:main Jun 9, 2026
4 checks passed
@af

af commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Nice PR, thank you!

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

Successfully merging this pull request may close these issues.

2 participants