summaryrefslogtreecommitdiff
path: root/tests/specs
diff options
context:
space:
mode:
authorBhuwan Pandit <bhuwanpandit109@gmail.com>2024-11-17 22:49:35 +0000
committerGitHub <noreply@github.com>2024-11-17 22:49:35 +0000
commitcff6e280c77afb0bc42a10348eeef5360db8f361 (patch)
treea6920ecc1358b23661145b3c03607787a04ae9c6 /tests/specs
parent73411bb98a677727799122ebc397d825bf95b812 (diff)
feat(cli): support multiple env file argument (#26527)
Closes #26425 ## Overview This PR adds support for specifying multiple environment files as arguments when using the Deno CLI. Subsequent files override pre-existing variables defined in previous files. If the same variable is defined in the environment and in the file, the value from the environment takes precedence. ## Example Usage ```bash deno run --allow-env --env-file --env-file=".env.one" --env-file=".env.two" script.ts ``` --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'tests/specs')
-rw-r--r--tests/specs/run/env_file/__test__.jsonc20
-rw-r--r--tests/specs/run/env_file/env4
-rw-r--r--tests/specs/run/env_file/env_file.out4
-rw-r--r--tests/specs/run/env_file/env_file.ts (renamed from tests/specs/run/env_unparsable_file/main.js)0
-rw-r--r--tests/specs/run/env_file/env_file_missing.out4
-rw-r--r--tests/specs/run/env_file/env_one2
-rw-r--r--tests/specs/run/env_file/env_two1
-rw-r--r--tests/specs/run/env_file/env_unparseable4
-rw-r--r--tests/specs/run/env_file/env_unparseable.out4
-rw-r--r--tests/specs/run/env_file/multiple_env_file.out4
-rw-r--r--tests/specs/run/env_unparsable_file/__test__.jsonc4
-rw-r--r--tests/specs/run/env_unparsable_file/main.out4
12 files changed, 47 insertions, 8 deletions
diff --git a/tests/specs/run/env_file/__test__.jsonc b/tests/specs/run/env_file/__test__.jsonc
new file mode 100644
index 000000000..642062169
--- /dev/null
+++ b/tests/specs/run/env_file/__test__.jsonc
@@ -0,0 +1,20 @@
+{
+ "tests": {
+ "basic": {
+ "args": "run --env=./env --allow-env env_file.ts",
+ "output": "env_file.out"
+ },
+ "missing": {
+ "args": "run --env=./missing --allow-env env_file.ts",
+ "output": "env_file_missing.out"
+ },
+ "multiple": {
+ "args": "run --env=./env --env=./env_one --env=./env_two --allow-env env_file.ts",
+ "output": "multiple_env_file.out"
+ },
+ "unparseable": {
+ "args": "run --env=./env_unparseable --allow-env env_file.ts",
+ "output": "env_unparseable.out"
+ }
+ }
+}
diff --git a/tests/specs/run/env_file/env b/tests/specs/run/env_file/env
new file mode 100644
index 000000000..c41732d30
--- /dev/null
+++ b/tests/specs/run/env_file/env
@@ -0,0 +1,4 @@
+FOO=BAR
+ANOTHER_FOO=ANOTHER_${FOO}
+MULTILINE="First Line
+Second Line" \ No newline at end of file
diff --git a/tests/specs/run/env_file/env_file.out b/tests/specs/run/env_file/env_file.out
new file mode 100644
index 000000000..54a0bf25d
--- /dev/null
+++ b/tests/specs/run/env_file/env_file.out
@@ -0,0 +1,4 @@
+BAR
+ANOTHER_BAR
+First Line
+Second Line
diff --git a/tests/specs/run/env_unparsable_file/main.js b/tests/specs/run/env_file/env_file.ts
index 48488ce72..48488ce72 100644
--- a/tests/specs/run/env_unparsable_file/main.js
+++ b/tests/specs/run/env_file/env_file.ts
diff --git a/tests/specs/run/env_file/env_file_missing.out b/tests/specs/run/env_file/env_file_missing.out
new file mode 100644
index 000000000..34b2bf810
--- /dev/null
+++ b/tests/specs/run/env_file/env_file_missing.out
@@ -0,0 +1,4 @@
+Warning The `--env-file` flag was used, but the environment file specified './missing' was not found.
+undefined
+undefined
+undefined
diff --git a/tests/specs/run/env_file/env_one b/tests/specs/run/env_file/env_one
new file mode 100644
index 000000000..c26038a67
--- /dev/null
+++ b/tests/specs/run/env_file/env_one
@@ -0,0 +1,2 @@
+FOO=BARBAR
+ANOTHER_FOO=OVERRIDEN_BY_ENV_ONE
diff --git a/tests/specs/run/env_file/env_two b/tests/specs/run/env_file/env_two
new file mode 100644
index 000000000..fe8392c3a
--- /dev/null
+++ b/tests/specs/run/env_file/env_two
@@ -0,0 +1 @@
+FOO=OVERRIDEN_BY_ENV_TWO
diff --git a/tests/specs/run/env_file/env_unparseable b/tests/specs/run/env_file/env_unparseable
new file mode 100644
index 000000000..5542b80bc
--- /dev/null
+++ b/tests/specs/run/env_file/env_unparseable
@@ -0,0 +1,4 @@
+FOO=valid
+ANOTHER_FOO=c:\path
+MULTILINE="First Line
+Second Line" \ No newline at end of file
diff --git a/tests/specs/run/env_file/env_unparseable.out b/tests/specs/run/env_file/env_unparseable.out
new file mode 100644
index 000000000..0a88d164e
--- /dev/null
+++ b/tests/specs/run/env_file/env_unparseable.out
@@ -0,0 +1,4 @@
+Warning Parsing failed within the specified environment file: ./env_unparseable at index: 3 of the value: c:\path
+valid
+undefined
+undefined
diff --git a/tests/specs/run/env_file/multiple_env_file.out b/tests/specs/run/env_file/multiple_env_file.out
new file mode 100644
index 000000000..3fa97d599
--- /dev/null
+++ b/tests/specs/run/env_file/multiple_env_file.out
@@ -0,0 +1,4 @@
+OVERRIDEN_BY_ENV_TWO
+OVERRIDEN_BY_ENV_ONE
+First Line
+Second Line
diff --git a/tests/specs/run/env_unparsable_file/__test__.jsonc b/tests/specs/run/env_unparsable_file/__test__.jsonc
deleted file mode 100644
index bed150635..000000000
--- a/tests/specs/run/env_unparsable_file/__test__.jsonc
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "args": "run --env=../../../testdata/env_unparsable --allow-env main.js",
- "output": "main.out"
-}
diff --git a/tests/specs/run/env_unparsable_file/main.out b/tests/specs/run/env_unparsable_file/main.out
deleted file mode 100644
index a19ff4dd6..000000000
--- a/tests/specs/run/env_unparsable_file/main.out
+++ /dev/null
@@ -1,4 +0,0 @@
-Warning Parsing failed within the specified environment file: ../../../testdata/env_unparsable at index: 3 of the value: c:\path
-valid
-undefined
-undefined