import { testDotenv } from "https://deno.land/x/enzastdlib@v0.0.4/environment/dotenv.ts";
Returns Error
objects of any validation errors that have occured regarding the
specified environment variables in a dotenv file, if any.
NOTE: To specify environment variables to test you MUST supply a JSON Schema that defines a top-level object.
NOTE: Only second-level keys are used for testing environment variables.
Examples
.env
.env
MY_STRING='Hello World!'
schema.ts
import type { JSONSchema } from 'https://deno.land/x/enzastdlib/schema/mod.ts';
export const MY_STRING_SCHEMA = {
type: 'object',
properties: {
MY_STRING: {
type: 'string',
minLength: 1,
},
},
} as const satisfies JSONSchema;
mod.ts
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
import { testDotenv } from 'https://deno.land/x/enzastdlib/environment/mod.ts';
import { MY_STRING_SCHEMA } from './schema.ts';
assertEquals(
testDotenv(MY_STRING_SCHEMA, {
envPath: './.env',
}),
undefined,
);
Parameters
schema: JSONSchemaObject