All checks were successful
Production PR / QA Tests (pull_request) Successful in 43s
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/* eslint-disable node/no-process-env */
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
describe("shared/utils/env", () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
process.env = { ...originalEnv };
|
|
process.env.NODE_ENV = "test";
|
|
process.env.NUXT_PUBLIC_SITE_URL = "http://localhost:3000";
|
|
process.env.DATABASE_URL = "postgres://localhost:5432/db";
|
|
process.env.BETTER_AUTH_SECRET = "secret";
|
|
process.env.BETTER_AUTH_URL = "http://localhost:3000";
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
it("should validate and export variables when all required variables are present", async () => {
|
|
const env = (await import("#shared/utils/env")).default;
|
|
|
|
expect(env).toEqual({
|
|
NODE_ENV: "test",
|
|
NUXT_PUBLIC_SITE_URL: "http://localhost:3000",
|
|
DATABASE_URL: "postgres://localhost:5432/db",
|
|
BETTER_AUTH_SECRET: "secret",
|
|
BETTER_AUTH_URL: "http://localhost:3000",
|
|
});
|
|
});
|
|
|
|
it("should throw an error if NODE_ENV is missing", async () => {
|
|
delete process.env.NODE_ENV;
|
|
await expect(import("#shared/utils/env")).rejects.toThrow(z.ZodError);
|
|
});
|
|
});
|