diff options
Diffstat (limited to 'test/cli/install/bun-install.test.ts')
-rw-r--r-- | test/cli/install/bun-install.test.ts | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/test/cli/install/bun-install.test.ts b/test/cli/install/bun-install.test.ts index d79155819..7def7d75f 100644 --- a/test/cli/install/bun-install.test.ts +++ b/test/cli/install/bun-install.test.ts @@ -2578,6 +2578,121 @@ it("should not hoist if name collides with alias", async () => { await access(join(package_dir, "bun.lockb")); }); +it("should get npm alias with matching version", async () => { + const urls: string[] = []; + setHandler( + dummyRegistry(urls, { + "0.0.3": { as: "0.0.3" }, + "0.0.5": { as: "0.0.5" }, + }), + ); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.0.1", + workspaces: ["moo"], + dependencies: { + "boba": "npm:baz@0.0.5", + }, + }), + ); + await mkdir(join(package_dir, "moo")); + await writeFile( + join(package_dir, "moo", "package.json"), + JSON.stringify({ + name: "moo", + version: "0.0.2", + dependencies: { + boba: ">=0.0.3", + }, + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + expect(stderr).toBeDefined(); + const err = await new Response(stderr).text(); + expect(err).toContain("Saved lockfile"); + expect(stdout).toBeDefined(); + const out = await new Response(stdout).text(); + expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + " + moo@workspace:moo", + " + boba@0.0.5", + "", + " 2 packages installed", + ]); + expect(await exited).toBe(0); + expect(urls.sort()).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.5.tgz`]); + expect(requested).toBe(2); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "boba", "moo"]); + expect(await file(join(package_dir, "node_modules", "boba", "package.json")).json()).toEqual({ + name: "baz", + version: "0.0.5", + bin: { + "baz-exec": "index.js", + }, + }); + await access(join(package_dir, "bun.lockb")); +}); + +it("should not apply overrides to package name of aliased package", async () => { + const urls: string[] = []; + setHandler( + dummyRegistry(urls, { + "0.0.3": { as: "0.0.3" }, + }), + ); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.2.0", + dependencies: { + bar: "npm:baz@0.0.3", + }, + overrides: { + "baz": "0.0.5", + }, + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install"], + cwd: package_dir, + stdout: null, + stdin: "pipe", + stderr: "pipe", + env, + }); + + expect(stderr).toBeDefined(); + const err = await new Response(stderr).text(); + expect(err).toContain("Saved lockfile"); + expect(stdout).toBeDefined(); + const out = await new Response(stdout).text(); + expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + " + bar@0.0.3", + "", + " 1 package installed", + ]); + expect(await exited).toBe(0); + expect(urls.sort()).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); + expect(requested).toBe(2); + expect(await file(join(package_dir, "node_modules", "bar", "package.json")).json()).toEqual({ + name: "baz", + version: "0.0.3", + bin: { + "baz-run": "index.js", + }, + }); + await access(join(package_dir, "bun.lockb")); +}); + it("should handle unscoped alias on scoped dependency", async () => { const urls: string[] = []; setHandler(dummyRegistry(urls, { "0.1.0": {} })); @@ -7434,6 +7549,51 @@ it("should install peer dependencies from root package", async () => { await access(join(package_dir, "bun.lockb")); }); +it("should install correct version of peer dependency from root package", async () => { + const urls: string[] = []; + setHandler( + dummyRegistry(urls, { + "0.0.3": { as: "0.0.3" }, + "0.0.5": { as: "0.0.5" }, + }), + ); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + dependencies: { + baz: "0.0.3", + }, + peerDependencies: { + baz: "0.0.5", + }, + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install"], + cwd: package_dir, + env, + stdout: null, + stdin: "pipe", + stderr: "pipe", + }); + expect(stderr).toBeDefined(); + const err = await new Response(stderr).text(); + expect(err).toContain("Saved lockfile"); + expect(stdout).toBeDefined(); + const out = await new Response(stdout).text(); + expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ + " + baz@0.0.3", + "", + " 1 package installed", + ]); + expect(await exited).toBe(0); + expect(urls.sort()).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); + expect(requested).toBe(2); + + await access(join(package_dir, "bun.lockb")); +}); + describe("Registry URLs", () => { // Some of the non failing URLs are invalid, but bun's URL parser ignores // the validation error and returns a valid serialized URL anyway. |