aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-08-15 18:40:00 -0700
committerGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-08-21 17:49:58 -0700
commit4003856575ec566ffbf51221d7782e9bda379d1d (patch)
treea9efbb903872e6d0dbac99082620eb303b475d90
parent2bb084e3f3184778556885ba1f3d22a862d57dff (diff)
downloadbun-4003856575ec566ffbf51221d7782e9bda379d1d.tar.gz
bun-4003856575ec566ffbf51221d7782e9bda379d1d.tar.zst
bun-4003856575ec566ffbf51221d7782e9bda379d1d.zip
Add test for absolute paths
-rw-r--r--test/cli/run/bunfig.test.ts47
-rw-r--r--test/harness.ts2
2 files changed, 49 insertions, 0 deletions
diff --git a/test/cli/run/bunfig.test.ts b/test/cli/run/bunfig.test.ts
index 0c8a23c65..efb4355ac 100644
--- a/test/cli/run/bunfig.test.ts
+++ b/test/cli/run/bunfig.test.ts
@@ -58,6 +58,17 @@ describe("config", () => {
}
});
+ test("read --config *.json absolute path", () => {
+ {
+ const dir = tempDirWithFiles("dotenv", {
+ "bun2.json": `{"define": { "caterpillar": "'butterfly'" }}`,
+ "index.ts": "console.log(caterpillar);",
+ });
+ const { stdout } = bunRun(`${dir}/index.ts`, {}, { flags: ["-c", `${dir}/bun2.json`] });
+ expect(stdout).toBe("butterfly");
+ }
+ });
+
test("read --config *.toml", () => {
{
const dir = tempDirWithFiles("dotenv", {
@@ -68,6 +79,7 @@ describe("config", () => {
expect(stdout).toBe("butterfly");
}
});
+
test("read -c *.toml", () => {
{
const dir = tempDirWithFiles("dotenv", {
@@ -78,4 +90,39 @@ describe("config", () => {
expect(stdout).toBe("butterfly");
}
});
+
+ test("read --config absolute path", () => {
+ {
+ const dir = tempDirWithFiles("dotenv", {
+ "bun2.toml": `[define]\n"caterpillar" = "'butterfly'"`,
+ "index.ts": "console.log(caterpillar);",
+ });
+ const { stdout } = bunRun(`${dir}/index.ts`, {}, { flags: ["-c", `${dir}/bun2.toml`] });
+ expect(stdout).toBe("butterfly");
+ }
+ });
+
+ test("fail if --config absolute path can't be found", () => {
+ {
+ const dir = tempDirWithFiles("dotenv", {
+ "index.ts": "console.log(caterpillar);",
+ });
+
+ {
+ expect(() => {
+ bunRun(`${dir}/index.ts`, {}, { flags: ["-c", `${dir}/notreal.json`] });
+ }).toThrow();
+ }
+ }
+ });
+ // test("read --config absolute path", () => {
+ // {
+ // const dir = tempDirWithFiles("dotenv", {
+ // "bun2.toml": `[define]\n"caterpillar" = "'butterfly'"`,
+ // "index.ts": "console.log(caterpillar);",
+ // });
+ // const { stdout } = bunRun(`${dir}/index.ts`, {}, { flags: ["-c", "bun2.toml"] });
+ // expect(stdout).toBe("butterfly");
+ // }
+ // });
});
diff --git a/test/harness.ts b/test/harness.ts
index 9643aff3d..8360ab3fd 100644
--- a/test/harness.ts
+++ b/test/harness.ts
@@ -119,6 +119,7 @@ export function bunRun(
});
if (!result.success) throw new Error(result.stderr.toString("utf8"));
return {
+ code: result.exitCode,
stdout: result.stdout.toString("utf8").trim(),
stderr: result.stderr.toString("utf8").trim(),
};
@@ -154,6 +155,7 @@ export function bunRunAsScript(dir: string, script: string, env?: Record<string,
if (!result.success) throw new Error(result.stderr.toString("utf8"));
return {
+ code: result.exitCode,
stdout: result.stdout.toString("utf8").trim(),
stderr: result.stderr.toString("utf8").trim(),
};