From a88e780aa3bae167e43a20f6212db7517f3da5ef Mon Sep 17 00:00:00 2001 From: Hexagon Date: Sat, 9 Mar 2024 01:28:40 +0000 Subject: [PATCH] Add .env-file for tests. Use node:fs/promises for all filesystem operations. Rename test file to allow clean deno test. --- .gitignore | 6 +++++- deno.jsonc | 2 +- lib/filehandler.ts | 8 ++------ tests/{deno.ts => mod.test.ts} | 0 4 files changed, 8 insertions(+), 8 deletions(-) rename tests/{deno.ts => mod.test.ts} (100%) diff --git a/.gitignore b/.gitignore index 1a469e8..b6e54cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ .env .env-local .vscode -test.ts \ No newline at end of file +test.ts +package.json +package-lock.json +deno.lock +node_modules \ No newline at end of file diff --git a/deno.jsonc b/deno.jsonc index e85863d..96b5e29 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -4,7 +4,7 @@ "exports": "./mod.ts", "tasks": { - "test": "deno test --allow-env --allow-read ./tests/deno.ts", + "test": "cd tests && deno test --allow-env --allow-read", "publish": "deno publish --config jsr.jsonc", "publish-dry": "deno publish --dry-run --config jsr.jsonc" }, diff --git a/lib/filehandler.ts b/lib/filehandler.ts index bab8a21..e46e71a 100644 --- a/lib/filehandler.ts +++ b/lib/filehandler.ts @@ -1,4 +1,5 @@ import { EnvOptions, FileReadError, UnsupportedEnvironmentError } from "./helpers.ts"; +import { readFile } from "node:fs/promises"; //Simulates/shims the Deno runtime for development purposes. declare const Deno: { @@ -35,14 +36,9 @@ export async function loadEnvFile( try { switch (currentRuntime) { case "deno": - fileContent = Deno.readTextFileSync(filePath); - break; case "bun": - fileContent = await Bun.file(filePath).text(); - break; case "node": { - const fs = await import("node:fs"); - fileContent = fs.readFileSync(filePath, "utf-8"); + fileContent = await readFile(filePath, "utf-8"); break; } default: diff --git a/tests/deno.ts b/tests/mod.test.ts similarity index 100% rename from tests/deno.ts rename to tests/mod.test.ts