forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix .env loader printing to stderr when running bun bun.lockb (oven-s…
…h#13905) Co-authored-by: Jarred Sumner <[email protected]>
- Loading branch information
1 parent
173f465
commit 043dfa4
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { file, listen, Socket, spawn } from "bun"; | ||
import { tmpdirSync } from "harness"; | ||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, setDefaultTimeout, test } from "bun:test"; | ||
import { access, mkdir, readlink, rm, writeFile, copyFile } from "fs/promises"; | ||
import { bunEnv, bunExe, bunEnv as env, tempDirWithFiles, toBeValidBin, toBeWorkspaceLink, toHaveBins } from "harness"; | ||
import { join, sep } from "path"; | ||
|
||
it("should not print anything to stderr when running bun.lockb", async () => { | ||
const package_dir = tmpdirSync(); | ||
|
||
// copy bar-0.0.2.tgz to package_dir | ||
await copyFile(join(__dirname, "bar-0.0.2.tgz"), join(package_dir, "bar-0.0.2.tgz")); | ||
|
||
// Create a simple package.json | ||
await writeFile( | ||
join(package_dir, "package.json"), | ||
JSON.stringify({ | ||
name: "test-package", | ||
version: "1.0.0", | ||
dependencies: { | ||
"dummy-package": "file:./bar-0.0.2.tgz", | ||
}, | ||
}), | ||
); | ||
|
||
// Run 'bun install' to generate the lockfile | ||
const installResult = spawn({ | ||
cmd: [bunExe(), "install"], | ||
cwd: package_dir, | ||
env, | ||
}); | ||
await installResult.exited; | ||
|
||
// Ensure the lockfile was created | ||
await access(join(package_dir, "bun.lockb")); | ||
|
||
// create a .env | ||
await writeFile(join(package_dir, ".env"), "FOO=bar"); | ||
|
||
// Now test 'bun bun.lockb' | ||
const { stdout, stderr, exited } = spawn({ | ||
cmd: [bunExe(), "bun.lockb"], | ||
cwd: package_dir, | ||
stdout: "pipe", | ||
stderr: "inherit", | ||
env, | ||
}); | ||
|
||
const stdoutOutput = await new Response(stdout).text(); | ||
expect(stdoutOutput).toBe( | ||
`# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n# yarn lockfile v1\n# bun ./bun.lockb --hash: 8B7A1C2DA8966A48-f4830e6e283fffe9-DE5BD0E91FD9910F-f0bf88071b3f7ec9\n\n\n\"bar@file:./bar-0.0.2.tgz\":\n version \"./bar-0.0.2.tgz\"\n resolved \"./bar-0.0.2.tgz\"\n`, | ||
); | ||
|
||
const stderrOutput = await new Response(stderr).text(); | ||
expect(stderrOutput).toBe(""); | ||
|
||
expect(await exited).toBe(0); | ||
}); |