Add core env loader

This commit is contained in:
2026-08-12 20:51:03 +02:00
parent a9a8fa7c3f
commit ca08ed9294
2 changed files with 28 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest';
import { z } from 'zod';
import { loadEnv } from '../../../src/core/config/env';
describe('loadEnv', () => {
const schema = z.object({
FOO: z.string(),
COUNT: z.coerce.number().default(5),
});
it('parses matching env vars into a typed object', () => {
const result = loadEnv(schema, { FOO: 'bar', COUNT: '10' });
expect(result).toEqual({ FOO: 'bar', COUNT: 10 });
});
it('throws a descriptive error when required vars are missing', () => {
expect(() => loadEnv(schema, {})).toThrow(/Invalid environment configuration/);
});
});