test: ensure that module is loaded after environment variable is set

This commit is contained in:
Jörg Krzeslak 2026-08-04 09:32:54 +02:00
parent 310a0652ec
commit 46705b6b34
1 changed files with 5 additions and 8 deletions

View File

@ -9,16 +9,13 @@ process.env.DB_PATH = join(testDbDir, "test.sqlite");
import { test, expect, afterAll, afterEach } from "bun:test";
import type { Cookie } from "elysia";
import {
getPossibleTargets,
getAllTargets,
getAllInputs,
handleConvert,
} from "../../src/converters/main";
import { writeFile, mkdir, rm, readFile } from "fs/promises";
import { Database } from "bun:sqlite";
// Import test-only exports (marked @internal in main.ts)
import { mainConverter, chunks } from "../../src/converters/main";
// dynamic import ensures that the module is loaded after the environment variable is set
const converterModule = await import("../../src/converters/main");
const { getPossibleTargets, getAllTargets, getAllInputs, handleConvert, mainConverter, chunks } =
converterModule;
// Isolated test database: avoids mutation of ./data/mydb.sqlite
const dbPath = process.env.DB_PATH ?? join(testDbDir, "test.sqlite");