aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js')
-rw-r--r--test/bun.js/install/bun-add.test.ts96
-rw-r--r--test/bun.js/install/bun-install.test.ts73
2 files changed, 164 insertions, 5 deletions
diff --git a/test/bun.js/install/bun-add.test.ts b/test/bun.js/install/bun-add.test.ts
index 42affcb70..cabc7820c 100644
--- a/test/bun.js/install/bun-add.test.ts
+++ b/test/bun.js/install/bun-add.test.ts
@@ -156,6 +156,102 @@ it("should reject invalid path without segfault", async () => {
});
});
+it("should handle semver-like names", async() => {
+ const urls: string[] = [];
+ setHandler(async (request) => {
+ expect(request.method).toBe("GET");
+ expect(request.headers.get("accept")).toBe(
+ "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*",
+ );
+ expect(request.headers.get("npm-auth-type")).toBe(null);
+ expect(await request.text()).toBe("");
+ urls.push(request.url);
+ return new Response("not to be found", { status: 404 });
+ });
+ await writeFile(join(package_dir, "package.json"), JSON.stringify({
+ name: "foo",
+ version: "0.0.1",
+ }));
+ const { stdout, stderr, exited } = spawn({
+ cmd: [
+ bunExe(),
+ "add",
+ "1.2.3",
+ "--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.split(/\r?\n/)).toContain(
+ 'error: package "1.2.3" not found localhost/1.2.3 404',
+ );
+ expect(stdout).toBeDefined();
+ expect(await new Response(stdout).text()).toBe("");
+ expect(await exited).toBe(1);
+ expect(urls).toEqual([`${root_url}/1.2.3`]);
+ expect(requested).toBe(1);
+ try {
+ await access(join(package_dir, "bun.lockb"));
+ expect(() => {}).toThrow();
+ } catch (err: any) {
+ expect(err.code).toBe("ENOENT");
+ }
+});
+
+it("should handle @scoped names", async() => {
+ const urls: string[] = [];
+ setHandler(async (request) => {
+ expect(request.method).toBe("GET");
+ expect(request.headers.get("accept")).toBe(
+ "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*",
+ );
+ expect(request.headers.get("npm-auth-type")).toBe(null);
+ expect(await request.text()).toBe("");
+ urls.push(request.url);
+ return new Response("not to be found", { status: 404 });
+ });
+ await writeFile(join(package_dir, "package.json"), JSON.stringify({
+ name: "foo",
+ version: "0.0.1",
+ }));
+ const { stdout, stderr, exited } = spawn({
+ cmd: [
+ bunExe(),
+ "add",
+ "@bar/baz",
+ "--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.split(/\r?\n/)).toContain(
+ 'error: package "@bar/baz" not found localhost/@bar/baz 404',
+ );
+ expect(stdout).toBeDefined();
+ expect(await new Response(stdout).text()).toBe("");
+ expect(await exited).toBe(1);
+ expect(urls).toEqual([`${root_url}/@bar/baz`]);
+ expect(requested).toBe(1);
+ try {
+ await access(join(package_dir, "bun.lockb"));
+ expect(() => {}).toThrow();
+ } catch (err: any) {
+ expect(err.code).toBe("ENOENT");
+ }
+});
+
it("should add dependency with specified semver", async () => {
const urls: string[] = [];
setHandler(dummyRegistry(urls, "0.0.3", {
diff --git a/test/bun.js/install/bun-install.test.ts b/test/bun.js/install/bun-install.test.ts
index 2bf59211e..7f5fe656e 100644
--- a/test/bun.js/install/bun-install.test.ts
+++ b/test/bun.js/install/bun-install.test.ts
@@ -1292,7 +1292,7 @@ it("should handle GitHub URL in dependencies (user/repo)", async () => {
"test",
"tools",
]);
- var package_json = await file(
+ const package_json = await file(
join(package_dir, "node_modules", "uglify", "package.json"),
).json();
expect(package_json.name).toBe("uglify-js");
@@ -1376,7 +1376,7 @@ it("should handle GitHub URL in dependencies (user/repo#commit-id)", async () =>
"test",
"tools",
]);
- var package_json = await file(
+ const package_json = await file(
join(package_dir, "node_modules", "uglify", "package.json"),
).json();
expect(package_json.name).toBe("uglify-js");
@@ -1461,7 +1461,7 @@ it("should handle GitHub URL in dependencies (user/repo#tag)", async () => {
"test",
"tools",
]);
- var package_json = await file(
+ const package_json = await file(
join(package_dir, "node_modules", "uglify", "package.json"),
).json();
expect(package_json.name).toBe("uglify-js");
@@ -1546,7 +1546,7 @@ it("should handle GitHub URL in dependencies (github:user/repo#tag)", async () =
"test",
"tools",
]);
- var package_json = await file(
+ const package_json = await file(
join(package_dir, "node_modules", "uglify", "package.json"),
).json();
expect(package_json.name).toBe("uglify-js");
@@ -1610,7 +1610,70 @@ it("should handle GitHub URL in dependencies (https://github.com/user/repo.git)"
"test",
"tools",
]);
- var package_json = await file(
+ const package_json = await file(
+ join(package_dir, "node_modules", "uglify", "package.json"),
+ ).json();
+ expect(package_json.name).toBe("uglify-js");
+ await access(join(package_dir, "bun.lockb"));
+});
+
+it("should handle GitHub URL in dependencies (git+https://github.com/user/repo.git)", async () => {
+ const urls: string[] = [];
+ setHandler(dummyRegistry(urls));
+ await writeFile(
+ join(package_dir, "package.json"),
+ JSON.stringify({
+ name: "Foo",
+ version: "0.0.1",
+ dependencies: {
+ uglify: "git+https://github.com/mishoo/UglifyJS.git",
+ },
+ }),
+ );
+ 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();
+ let out = await new Response(stdout).text();
+ out = out.replace(/\s*\[[0-9\.]+ms\]\s*$/, "");
+ out = out.replace(/(github:[^#]+)#[a-f0-9]+/, "$1");
+ expect(out.split(/\r?\n/)).toEqual([
+ " + uglify@github:mishoo/UglifyJS",
+ "",
+ " 1 packages installed",
+ ]);
+ expect(await exited).toBe(0);
+ expect(urls).toEqual([]);
+ expect(requested).toBe(0);
+ expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([
+ ".bin",
+ ".cache",
+ "uglify",
+ ]);
+ expect(await readdirSorted(join(package_dir, "node_modules", ".bin"))).toEqual(["uglifyjs"]);
+ expect(await readdirSorted(join(package_dir, "node_modules", "uglify"))).toEqual([
+ ".bun-tag",
+ ".gitattributes",
+ ".github",
+ ".gitignore",
+ "CONTRIBUTING.md",
+ "LICENSE",
+ "README.md",
+ "bin",
+ "lib",
+ "package.json",
+ "test",
+ "tools",
+ ]);
+ const package_json = await file(
join(package_dir, "node_modules", "uglify", "package.json"),
).json();
expect(package_json.name).toBe("uglify-js");