aboutsummaryrefslogtreecommitdiff
path: root/test/js
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-08-28 14:58:31 +0800
committerGravatar GitHub <noreply@github.com> 2023-08-27 23:58:31 -0700
commitefe987e8d12e824dde840b56cbb704feabe26ed1 (patch)
treea01daf0092aca085cafcd6a4a6d95d9ad7b2e7fe /test/js
parented5dc5bbf922777acd3f637125a1978b6f2c391a (diff)
downloadbun-efe987e8d12e824dde840b56cbb704feabe26ed1.tar.gz
bun-efe987e8d12e824dde840b56cbb704feabe26ed1.tar.zst
bun-efe987e8d12e824dde840b56cbb704feabe26ed1.zip
Fix some edge cases in the `env` param of `spawn`. (#4364)
Close: #4362
Diffstat (limited to 'test/js')
-rw-r--r--test/js/node/child_process/child_process.test.ts23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/js/node/child_process/child_process.test.ts b/test/js/node/child_process/child_process.test.ts
index 24b3b5e48..8c54a11c5 100644
--- a/test/js/node/child_process/child_process.test.ts
+++ b/test/js/node/child_process/child_process.test.ts
@@ -149,13 +149,24 @@ describe("spawn()", () => {
});
it("should allow us to set env", async () => {
- const child = spawn("env", { env: { TEST: "test" } });
- const result: string = await new Promise(resolve => {
- child.stdout.on("data", data => {
- resolve(data.toString());
+ async function getChildEnv(env: any): Promise<string> {
+ const child = spawn("env", { env: env });
+ const result: string = await new Promise(resolve => {
+ let output = "";
+ child.stdout.on("data", data => {
+ output += data;
+ });
+ child.stdout.on("end", () => {
+ resolve(output);
+ });
});
- });
- expect(/TEST\=test/.test(result)).toBe(true);
+ return result;
+ }
+
+ expect(/TEST\=test/.test(await getChildEnv({ TEST: "test" }))).toBe(true);
+ expect(await getChildEnv({})).toStrictEqual("");
+ expect(await getChildEnv(undefined)).not.toStrictEqual("");
+ expect(await getChildEnv(null)).not.toStrictEqual("");
});
it("should allow explicit setting of argv0", async () => {