-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test for plaintext lockfiles
- Loading branch information
1 parent
4401c23
commit af9f6d2
Showing
2 changed files
with
47 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { spawn } from "bun"; | ||
import { expect, it } from "bun:test"; | ||
import { access, copyFile, open, writeFile } from "fs/promises"; | ||
import { bunExe, bunEnv as env, tmpdirSync } from "harness"; | ||
import { join } from "path"; | ||
|
||
it("should write plaintext lockfiles", 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", "--save-text-lockfile"], | ||
cwd: package_dir, | ||
env, | ||
}); | ||
await installResult.exited; | ||
|
||
// Ensure the lockfile was created | ||
await access(join(package_dir, "bun.lock")); | ||
|
||
// Assert that the lockfile has the correct permissions | ||
const file = await open(join(package_dir, "bun.lock"), "r"); | ||
const stat = await file.stat(); | ||
// 0o644 == 33188 | ||
expect(stat.mode).toBe(33188); | ||
|
||
expect(await file.readFile({ encoding: "utf8" })).toEqual( | ||
`{\n \"lockfileVersion\": 0,\n \"workspaces\": {\n \"\": {\n \"dependencies\": {\n \"dummy-package\": \"file:./bar-0.0.2.tgz\",\n },\n },\n },\n \"packages\": {\n \"dummy-package\": [\"bar@./bar-0.0.2.tgz\", {}],\n }\n}\n`, | ||
); | ||
}); |
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