diff options
Diffstat (limited to 'test/bun.js')
-rw-r--r-- | test/bun.js/install/bar-0.0.2.tgz (renamed from test/bun.js/install/bar.tgz) | bin | 192 -> 192 bytes | |||
-rw-r--r-- | test/bun.js/install/baz-0.0.3.tgz (renamed from test/bun.js/install/baz.tgz) | bin | 283 -> 283 bytes | |||
-rw-r--r-- | test/bun.js/install/baz-0.0.5.tgz | bin | 0 -> 286 bytes | |||
-rw-r--r-- | test/bun.js/install/bun-add.test.ts | 39 | ||||
-rw-r--r-- | test/bun.js/install/bun-install.test.ts | 237 | ||||
-rw-r--r-- | test/bun.js/install/bun-link.test.ts | 6 | ||||
-rw-r--r-- | test/bun.js/install/dummy.registry.ts | 30 |
7 files changed, 245 insertions, 67 deletions
diff --git a/test/bun.js/install/bar.tgz b/test/bun.js/install/bar-0.0.2.tgz Binary files differindex 1983142d7..1983142d7 100644 --- a/test/bun.js/install/bar.tgz +++ b/test/bun.js/install/bar-0.0.2.tgz diff --git a/test/bun.js/install/baz.tgz b/test/bun.js/install/baz-0.0.3.tgz Binary files differindex 375a5e31f..375a5e31f 100644 --- a/test/bun.js/install/baz.tgz +++ b/test/bun.js/install/baz-0.0.3.tgz diff --git a/test/bun.js/install/baz-0.0.5.tgz b/test/bun.js/install/baz-0.0.5.tgz Binary files differnew file mode 100644 index 000000000..7e708fb1b --- /dev/null +++ b/test/bun.js/install/baz-0.0.5.tgz diff --git a/test/bun.js/install/bun-add.test.ts b/test/bun.js/install/bun-add.test.ts index 0729e4e52..57c76640b 100644 --- a/test/bun.js/install/bun-add.test.ts +++ b/test/bun.js/install/bun-add.test.ts @@ -2,7 +2,7 @@ import { file, spawn } from "bun"; import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test"; import { bunExe } from "bunExe"; import { bunEnv as env } from "bunEnv"; -import { access, mkdir, mkdtemp, readlink, rm, writeFile } from "fs/promises"; +import { access, mkdir, mkdtemp, readlink, realpath, rm, writeFile } from "fs/promises"; import { join, relative } from "path"; import { tmpdir } from "os"; import { @@ -17,7 +17,6 @@ import { root_url, setHandler, } from "./dummy.registry"; -import { realpathSync } from "fs"; beforeAll(dummyBeforeAll); afterAll(dummyAfterAll); @@ -25,7 +24,7 @@ afterAll(dummyAfterAll); let add_dir; beforeEach(async () => { - add_dir = await mkdtemp(join(realpathSync(tmpdir()), "bun-add.test")); + add_dir = await mkdtemp(join(await realpath(tmpdir()), "bun-add.test")); await dummyBeforeEach(); }); afterEach(async () => { @@ -243,9 +242,11 @@ it("should handle @scoped names", async () => { it("should add dependency with specified semver", async () => { const urls: string[] = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -278,7 +279,7 @@ it("should add dependency with specified semver", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "baz"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -304,9 +305,11 @@ it("should add dependency with specified semver", async () => { it("should add dependency alongside workspaces", async () => { const urls: string[] = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -349,7 +352,7 @@ it("should add dependency alongside workspaces", async () => { " 2 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "bar", "baz"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -377,9 +380,11 @@ it("should add dependency alongside workspaces", async () => { it("should add aliased dependency (npm)", async () => { const urls: string[] = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -412,7 +417,7 @@ it("should add aliased dependency (npm)", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -510,7 +515,7 @@ it("should add aliased dependency (GitHub)", async () => { it("should let you add the same package twice", async () => { const urls: string[] = []; - setHandler(dummyRegistry(urls, "0.0.3", {})); + setHandler(dummyRegistry(urls, { "0.0.3": {} })); await writeFile( join(package_dir, "package.json"), JSON.stringify({ @@ -540,7 +545,7 @@ it("should let you add the same package twice", async () => { expect(out1).toContain("installed baz@0.0.3"); expect(out1).toContain("1 packages installed"); expect(await exited1).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "baz"]); expect(await file(join(package_dir, "node_modules", "baz", "package.json")).json()).toEqual({ diff --git a/test/bun.js/install/bun-install.test.ts b/test/bun.js/install/bun-install.test.ts index 048c15c6f..42d19193c 100644 --- a/test/bun.js/install/bun-install.test.ts +++ b/test/bun.js/install/bun-install.test.ts @@ -135,7 +135,7 @@ it("should handle empty string in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -462,6 +462,49 @@ it("should handle life-cycle scripts within workspaces", async () => { await access(join(package_dir, "bun.lockb")); }); +it("should ignore workspaces within workspaces", async () => { + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.0.1", + workspaces: ["bar"], + }), + ); + await mkdir(join(package_dir, "bar")); + await writeFile( + join(package_dir, "bar", "package.json"), + JSON.stringify({ + name: "bar", + version: "0.0.2", + workspaces: ["baz"], + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"], + 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@workspace:bar", + "", + " 1 packages installed", + ]); + expect(await exited).toBe(0); + expect(requested).toBe(0); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); + expect(await readlink(join(package_dir, "node_modules", "bar"))).toBe(join("..", "bar")); + await access(join(package_dir, "bun.lockb")); +}); + it("should handle ^0 in dependencies", async () => { const urls: string[] = []; setHandler(dummyRegistry(urls)); @@ -494,7 +537,7 @@ it("should handle ^0 in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -574,7 +617,7 @@ it("should handle ^0.0 in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -691,7 +734,7 @@ it("should handle ^0.0.2 in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -704,7 +747,7 @@ it("should handle ^0.0.2 in dependencies", async () => { it("should handle ^0.0.2-rc in dependencies", async () => { const urls: string[] = []; - setHandler(dummyRegistry(urls, "0.0.2-rc")); + setHandler(dummyRegistry(urls, { "0.0.2-rc": { as: "0.0.2" } })); await writeFile( join(package_dir, "package.json"), JSON.stringify({ @@ -734,7 +777,7 @@ it("should handle ^0.0.2-rc in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -747,7 +790,7 @@ it("should handle ^0.0.2-rc in dependencies", async () => { it("should handle ^0.0.2-alpha.3+b4d in dependencies", async () => { const urls: string[] = []; - setHandler(dummyRegistry(urls, "0.0.2-alpha.3")); + setHandler(dummyRegistry(urls, { "0.0.2-alpha.3": { as: "0.0.2" } })); await writeFile( join(package_dir, "package.json"), JSON.stringify({ @@ -777,7 +820,7 @@ it("should handle ^0.0.2-alpha.3+b4d in dependencies", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([`${root_url}/bar`, `${root_url}/bar-0.0.2.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar"]); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["package.json"]); @@ -791,9 +834,11 @@ it("should handle ^0.0.2-alpha.3+b4d in dependencies", async () => { it("should handle dependency aliasing", async () => { const urls = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -826,7 +871,7 @@ it("should handle dependency aliasing", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "Bar"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -845,9 +890,11 @@ it("should handle dependency aliasing", async () => { it("should handle dependency aliasing (versioned)", async () => { const urls: string[] = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -880,7 +927,7 @@ it("should handle dependency aliasing (versioned)", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "Bar"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -899,9 +946,11 @@ it("should handle dependency aliasing (versioned)", async () => { it("should handle dependency aliasing (dist-tagged)", async () => { const urls: string[] = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -934,7 +983,7 @@ it("should handle dependency aliasing (dist-tagged)", async () => { " 1 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "Bar"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -953,9 +1002,11 @@ it("should handle dependency aliasing (dist-tagged)", async () => { it("should not reinstall aliased dependencies", async () => { const urls = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -992,7 +1043,7 @@ it("should not reinstall aliased dependencies", async () => { " 1 packages installed", ]); expect(await exited1).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "Bar"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -1049,9 +1100,11 @@ it("should not reinstall aliased dependencies", async () => { it("should handle aliased & direct dependency references", async () => { const urls = []; setHandler( - dummyRegistry(urls, "0.0.3", { - bin: { - "baz-run": "index.js", + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, }, }), ); @@ -1097,7 +1150,7 @@ it("should handle aliased & direct dependency references", async () => { " 2 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz.tgz`]); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`]); expect(requested).toBe(2); expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "bar", "baz"]); expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); @@ -1126,7 +1179,16 @@ it("should handle aliased & direct dependency references", async () => { it("should not hoist if name collides with alias", async () => { const urls = []; - setHandler(dummyRegistry(urls)); + setHandler( + dummyRegistry(urls, { + "0.0.2": {}, + "0.0.3": { + bin: { + "baz-run": "index.js", + }, + }, + }), + ); await writeFile( join(package_dir, "package.json"), JSON.stringify({ @@ -1145,7 +1207,7 @@ it("should not hoist if name collides with alias", async () => { name: "moo", version: "0.0.4", dependencies: { - bar: "*", + bar: "0.0.2", }, }), ); @@ -1164,14 +1226,21 @@ it("should not hoist if name collides with alias", async () => { const out = await new Response(stdout).text(); expect(out.replace(/\s*\[[0-9\.]+m?s\]\s*$/, "").split(/\r?\n/)).toEqual([ " + moo@workspace:moo", - " + bar@0.0.2", + " + bar@0.0.3", "", " 3 packages installed", ]); expect(await exited).toBe(0); - expect(urls).toEqual([`${root_url}/baz`, `${root_url}/bar`, `${root_url}/baz.tgz`, `${root_url}/bar.tgz`]); + expect(urls).toEqual([ + `${root_url}/baz`, + `${root_url}/bar`, + `${root_url}/baz-0.0.3.tgz`, + `${root_url}/bar-0.0.2.tgz`, + ]); expect(requested).toBe(4); - expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "bar", "moo"]); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "bar", "moo"]); + expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-run"]); + expect(await readlink(join(package_dir, "node_modules", ".bin", "baz-run"))).toBe(join("..", "bar", "index.js")); expect(await readdirSorted(join(package_dir, "node_modules", "bar"))).toEqual(["index.js", "package.json"]); expect(await file(join(package_dir, "node_modules", "bar", "package.json")).json()).toEqual({ name: "baz", @@ -1550,3 +1619,105 @@ it("should handle GitHub URL in dependencies (git+https://github.com/user/repo.g expect(package_json.name).toBe("uglify-js"); await access(join(package_dir, "bun.lockb")); }); + +it("should consider peerDependencies during hoisting", async () => { + const urls = []; + setHandler( + dummyRegistry(urls, { + "0.0.3": { + bin: { + "baz-run": "index.js", + }, + }, + "0.0.5": { + bin: { + "baz-exec": "index.js", + }, + }, + }), + ); + await writeFile( + join(package_dir, "package.json"), + JSON.stringify({ + name: "foo", + version: "0.0.1", + peerDependencies: { + baz: ">0.0.3", + }, + workspaces: ["bar", "moo"], + }), + ); + await mkdir(join(package_dir, "bar")); + await writeFile( + join(package_dir, "bar", "package.json"), + JSON.stringify({ + name: "bar", + version: "0.0.2", + dependencies: { + baz: "0.0.3", + }, + }), + ); + await mkdir(join(package_dir, "moo")); + await writeFile( + join(package_dir, "moo", "package.json"), + JSON.stringify({ + name: "moo", + version: "0.0.4", + dependencies: { + baz: "0.0.5", + }, + }), + ); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml", "--peer"], + 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@workspace:bar", + " + moo@workspace:moo", + " + baz@0.0.5", + "", + " 4 packages installed", + ]); + expect(await exited).toBe(0); + expect(urls).toEqual([`${root_url}/baz`, `${root_url}/baz-0.0.3.tgz`, `${root_url}/baz-0.0.5.tgz`]); + expect(requested).toBe(3); + expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".bin", ".cache", "bar", "baz", "moo"]); + expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["baz-exec", "baz-run"]); + expect(await readlink(join(package_dir, "node_modules", ".bin", "baz-exec"))).toBe(join("..", "baz", "index.js")); + expect(await readlink(join(package_dir, "node_modules", ".bin", "baz-run"))).toBe( + join("..", "bar", "node_modules", "baz", "index.js"), + ); + expect(await readlink(join(package_dir, "node_modules", "bar"))).toBe(join("..", "bar")); + expect(await readdirSorted(join(package_dir, "bar"))).toEqual(["node_modules", "package.json"]); + expect(await readdirSorted(join(package_dir, "bar", "node_modules"))).toEqual(["baz"]); + expect(await readdirSorted(join(package_dir, "bar", "node_modules", "baz"))).toEqual(["index.js", "package.json"]); + expect(await file(join(package_dir, "bar", "node_modules", "baz", "package.json")).json()).toEqual({ + name: "baz", + version: "0.0.3", + bin: { + "baz-run": "index.js", + }, + }); + expect(await readdirSorted(join(package_dir, "node_modules", "baz"))).toEqual(["index.js", "package.json"]); + expect(await file(join(package_dir, "node_modules", "baz", "package.json")).json()).toEqual({ + name: "baz", + version: "0.0.5", + bin: { + "baz-exec": "index.js", + }, + }); + expect(await readlink(join(package_dir, "node_modules", "moo"))).toBe(join("..", "moo")); + expect(await readdirSorted(join(package_dir, "moo"))).toEqual(["package.json"]); + await access(join(package_dir, "bun.lockb")); +}); diff --git a/test/bun.js/install/bun-link.test.ts b/test/bun.js/install/bun-link.test.ts index 5e80216bd..b892c00e0 100644 --- a/test/bun.js/install/bun-link.test.ts +++ b/test/bun.js/install/bun-link.test.ts @@ -2,15 +2,15 @@ import { spawn } from "bun"; import { afterEach, beforeEach, expect, it } from "bun:test"; import { bunExe } from "bunExe"; import { bunEnv as env } from "bunEnv"; -import { mkdtemp, rm, writeFile } from "fs/promises"; +import { mkdtemp, realpath, rm, writeFile } from "fs/promises"; import { basename, join } from "path"; import { tmpdir } from "os"; let package_dir, link_dir; beforeEach(async () => { - link_dir = await mkdtemp(join(tmpdir(), "bun-link.test")); - package_dir = await mkdtemp(join(tmpdir(), "bun-link.pkg")); + link_dir = await mkdtemp(join(await realpath(tmpdir()), "bun-link.test")); + package_dir = await mkdtemp(join(await realpath(tmpdir()), "bun-link.pkg")); }); afterEach(async () => { await rm(link_dir, { force: true, recursive: true }); diff --git a/test/bun.js/install/dummy.registry.ts b/test/bun.js/install/dummy.registry.ts index 9738591cc..179231ed1 100644 --- a/test/bun.js/install/dummy.registry.ts +++ b/test/bun.js/install/dummy.registry.ts @@ -1,14 +1,13 @@ import { file } from "bun"; import { expect } from "bun:test"; -import { realpathSync } from "fs"; -import { mkdtemp, readdir, rm } from "fs/promises"; +import { mkdtemp, readdir, realpath, rm } from "fs/promises"; import { tmpdir } from "os"; import { basename, join } from "path"; let handler, server; export let package_dir, requested, root_url; -export function dummyRegistry(urls, version = "0.0.2", props = {}) { +export function dummyRegistry(urls, info: object = { "0.0.2": {} }) { return async request => { urls.push(request.url); expect(request.method).toBe("GET"); @@ -21,19 +20,22 @@ export function dummyRegistry(urls, version = "0.0.2", props = {}) { expect(request.headers.get("npm-auth-type")).toBe(null); expect(await request.text()).toBe(""); const name = request.url.slice(request.url.lastIndexOf("/") + 1); + const versions = {}; + let version; + for (version in info) { + versions[version] = { + name, + version, + dist: { + tarball: `${request.url}-${info[version].as ?? version}.tgz`, + }, + ...info[version], + }; + } return new Response( JSON.stringify({ name, - versions: { - [version]: { - name, - version, - dist: { - tarball: `${request.url}.tgz`, - }, - ...props, - }, - }, + versions, "dist-tags": { latest: version, }, @@ -74,7 +76,7 @@ export function dummyAfterAll() { export async function dummyBeforeEach() { resetHanlder(); requested = 0; - package_dir = realpathSync(await mkdtemp(join(tmpdir(), "bun-install.test"))); + package_dir = await mkdtemp(join(await realpath(tmpdir()), "bun-install.test")); } export async function dummyAfterEach() { |