Skip to content

test(config): add unit tests - #295

Merged
Komoszek merged 2 commits into
mainfrom
test/config
Jun 25, 2026
Merged

Komoszek merged 2 commits into
mainfrom
test/config

Conversation

@claude

@claude claude Bot commented Jun 25, 2026

Copy link
Copy Markdown

Requested by Sebastian Konowrocki · Slack thread

Before / After

The @leancodepl/config package had no tests. This adds 9 unit tests covering mkGetInjectedConfig, the package's only public API:

  • Returns an object exposing a getInjectedConfig function
  • Reads values from import.meta.env using the VITE_ prefix
  • Uses the prefixed key only — never the raw, unprefixed key
  • Returns undefined for unset variables
  • Distinguishes an explicitly-empty string from an unset value
  • Reflects updated env values on each call (no value caching)
  • Resolves multiple independent keys from a single getter
  • Produces independent getter instances sharing the same underlying env
  • Does not collide with similarly-named keys lacking the exact prefix (VITE_FOOBAR vs FOO)

How

Added src/index.spec.ts using vitest with vi.stubEnv to drive import.meta.env, mirroring the sibling @leancodepl/logger test conventions. Added vitest to the package's devDependencies so the spec import resolves under the lint rules. :test, :typecheck, :lint, and :build all pass.


Generated by Claude Code

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@claude
claude Bot marked this pull request as ready for review June 25, 2026 09:35
Comment thread packages/config/src/index.spec.ts Outdated
Comment on lines +9 to +14
it("returns an object exposing getInjectedConfig", () => {
const result = mkGetInjectedConfig()

expect(result).toHaveProperty("getInjectedConfig")
expect(typeof result.getInjectedConfig).toBe("function")
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this necessary? Isn't it enforced by typescript and other tests?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Masz rację — getInjectedConfig to typowany literał obiektu, więc TS już gwarantuje, że pole istnieje i jest funkcją. Dodatkowo każdy kolejny test destrukturyzuje i wywołuje ten getter, więc jego obecność i wywoływalność są pokryte runtime'owo. Usunąłem ten test.

The test only asserted the static object shape (getInjectedConfig exists
and is a function), which TypeScript already guarantees from the typed
object literal returned by mkGetInjectedConfig. It is also exercised at
runtime by every other test that destructures and calls getInjectedConfig.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXXPnGepYUGie3we1X9PTR
@Komoszek
Komoszek merged commit d3244e9 into main Jun 25, 2026
1 check passed
@Komoszek
Komoszek deleted the test/config branch June 25, 2026 12:44
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