aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cli/run/env.test.ts43
1 files changed, 42 insertions, 1 deletions
diff --git a/test/cli/run/env.test.ts b/test/cli/run/env.test.ts
index 159793e27..3ed300477 100644
--- a/test/cli/run/env.test.ts
+++ b/test/cli/run/env.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test";
-import { bunRun, bunTest, tempDirWithFiles, bunExe, bunEnv } from "harness";
+import { bunRun, bunRunAsScript, bunTest, tempDirWithFiles, bunExe, bunEnv } from "harness";
import path from "path";
function bunRunWithoutTrim(file: string, env?: Record<string, string>) {
@@ -255,6 +255,47 @@ test(".env process variables no comments", () => {
expect(stdout).toBe('test#1 "test#2"');
});
+describe("package scripts load from .env.production and .env.development", () => {
+ test("NODE_ENV=production", () => {
+ const dir = tempDirWithFiles("dotenv-package-script-prod", {
+ "index.ts": "console.log(process.env.TEST);",
+ "package.json": `
+ {
+ "name": "foo",
+ "version": "2.0",
+ "scripts": {
+ "test": "NODE_ENV=production ${bunExe()} run index.ts",
+ }
+ }
+ `,
+ ".env.production": "TEST=prod",
+ ".env.development": "TEST=dev",
+ });
+
+ const { stdout } = bunRunAsScript(dir, "test");
+ expect(stdout).toBe("prod");
+ });
+ test("NODE_ENV=development", () => {
+ const dir = tempDirWithFiles("dotenv-package-script-prod", {
+ "index.ts": "console.log(process.env.TEST);",
+ "package.json": `
+ {
+ "name": "foo",
+ "version": "2.0",
+ "scripts": {
+ "test": "NODE_ENV=development ${bunExe()} run index.ts",
+ }
+ }
+ `,
+ ".env.production": "TEST=prod",
+ ".env.development": "TEST=dev",
+ });
+
+ const { stdout } = bunRunAsScript(dir, "test");
+ expect(stdout).toBe("dev");
+ });
+});
+
test(".env escaped dollar sign", () => {
const dir = tempDirWithFiles("dotenv-dollar", {
".env": "FOO=foo\nBAR=\\$FOO",