diff --git a/init.ts b/init.ts index 8f9d9418..fd7969ed 100644 --- a/init.ts +++ b/init.ts @@ -538,6 +538,8 @@ const DEV_TS = `#!/usr/bin/env -S deno run -A --watch=static/,routes/ import dev from "$fresh/dev.ts"; import config from "./fresh.config.ts"; +import "$std/dotenv/load.ts"; + await dev(import.meta.url, "./main.ts", config); `; const DEV_TS_PATH = join(resolvedDirectory, "dev.ts"); diff --git a/tests/cli_test.ts b/tests/cli_test.ts index e34f051b..0d34eb7f 100644 --- a/tests/cli_test.ts +++ b/tests/cli_test.ts @@ -12,7 +12,9 @@ import { retry, } from "./deps.ts"; import { + assertTextMany, clickWhenListenerReady, + fetchHtml, startFreshServer, waitForText, } from "./test_utils.ts"; @@ -367,6 +369,84 @@ Deno.test({ sanitizeResources: false, }); +Deno.test({ + name: "fresh-init loads env variables", + async fn(t) { + // Preparation + const tmpDirName = await Deno.makeTempDir(); + + const cliProcess = new Deno.Command(Deno.execPath(), { + args: [ + "run", + "-A", + "init.ts", + tmpDirName, + "--twind", + "--vscode", + ], + stdin: "null", + stdout: "piped", + stderr: "inherit", + }); + + await cliProcess.output(); + + // Add .env file + await Deno.writeTextFile(path.join(tmpDirName, ".env"), "FOO=true\n"); + await Deno.writeTextFile( + path.join(tmpDirName, "routes", "env.tsx"), + `export default function Page() { return