aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-03-05 18:09:17 +0200
committerGravatar GitHub <noreply@github.com> 2023-03-05 08:09:17 -0800
commit67422785cc593003813d500c13919d35cd4259b0 (patch)
tree1b3e99e6c0d2a74a05b743c0cefae3a1062d8cbf
parent42f6b35a5be8bc0b48f7643618a8458c146e8272 (diff)
downloadbun-67422785cc593003813d500c13919d35cd4259b0.tar.gz
bun-67422785cc593003813d500c13919d35cd4259b0.tar.zst
bun-67422785cc593003813d500c13919d35cd4259b0.zip
[install] fix connection error detection (#2307)
-rw-r--r--src/http_client_async.zig3
-rw-r--r--test/bun.js/install/basic.toml6
-rw-r--r--test/bun.js/install/bun-add.test.ts30
-rw-r--r--test/bun.js/install/bun-install.test.ts165
-rw-r--r--test/bun.js/install/bun-link.test.ts2
-rw-r--r--test/bun.js/install/bun-pm.test.ts8
-rw-r--r--test/bun.js/install/dummy.registry.ts14
7 files changed, 146 insertions, 82 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 945406448..0033d8ad0 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -1335,14 +1335,15 @@ pub const AsyncHTTP = struct {
std.debug.assert(active_requests > 0);
var completion = this.completion_callback;
- this.response = result.response;
this.elapsed = http_thread.timer.read() -| this.elapsed;
this.redirected = this.client.remaining_redirect_count != default_redirect_count;
if (!result.isSuccess()) {
this.err = result.fail;
+ this.response = null;
this.state.store(State.fail, .Monotonic);
} else {
this.err = null;
+ this.response = result.response;
this.state.store(.success, .Monotonic);
}
this.client.deinit();
diff --git a/test/bun.js/install/basic.toml b/test/bun.js/install/basic.toml
deleted file mode 100644
index a8476663a..000000000
--- a/test/bun.js/install/basic.toml
+++ /dev/null
@@ -1,6 +0,0 @@
-[install]
-cache = false
-registry = "http://localhost:54321/"
-
-[install.scopes]
-foo = { token = "bar" } \ No newline at end of file
diff --git a/test/bun.js/install/bun-add.test.ts b/test/bun.js/install/bun-add.test.ts
index ada3c4b58..9ac54bbc5 100644
--- a/test/bun.js/install/bun-add.test.ts
+++ b/test/bun.js/install/bun-add.test.ts
@@ -173,7 +173,7 @@ it("should handle semver-like names", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "1.2.3", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "1.2.3"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -216,7 +216,7 @@ it("should handle @scoped names", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "@bar/baz", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "@bar/baz"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -250,7 +250,7 @@ it("should add dependency with capital letters", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "BaR", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "BaR"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -307,7 +307,7 @@ it("should add dependency with specified semver", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "baz@~0.0.2", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "baz@~0.0.2"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -379,7 +379,7 @@ it("should add dependency alongside workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "baz", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "baz"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -445,7 +445,7 @@ it("should add aliased dependency (npm)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "bar@npm:baz@~0.0.2", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "bar@npm:baz@~0.0.2"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -500,7 +500,7 @@ it("should add aliased dependency (GitHub)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "uglify@mishoo/UglifyJS#v3.14.1", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "uglify@mishoo/UglifyJS#v3.14.1"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -579,7 +579,7 @@ it("should let you add the same package twice", async () => {
stderr: stderr1,
exited: exited1,
} = spawn({
- cmd: [bunExe(), "add", "baz@0.0.3", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "baz@0.0.3"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -624,7 +624,7 @@ it("should let you add the same package twice", async () => {
stderr: stderr2,
exited: exited2,
} = spawn({
- cmd: [bunExe(), "add", "baz", "-d", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "baz", "-d"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -680,7 +680,7 @@ it("should install version tagged with `latest` by default", async () => {
stderr: stderr1,
exited: exited1,
} = spawn({
- cmd: [bunExe(), "add", "baz", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "baz"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -726,7 +726,7 @@ it("should install version tagged with `latest` by default", async () => {
stderr: stderr2,
exited: exited2,
} = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -779,7 +779,7 @@ it("should handle Git URL in dependencies (SCP-style)", async () => {
stderr: stderr1,
exited: exited1,
} = spawn({
- cmd: [bunExe(), "add", "bun@github.com:mishoo/UglifyJS.git", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "bun@github.com:mishoo/UglifyJS.git"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -839,7 +839,7 @@ it("should handle Git URL in dependencies (SCP-style)", async () => {
stderr: stderr2,
exited: exited2,
} = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -877,7 +877,7 @@ it("should prefer optionalDependencies over dependencies of the same name", asyn
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "bar@0.0.2", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "bar@0.0.2"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -937,7 +937,7 @@ it("should prefer dependencies over peerDependencies of the same name", async ()
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "add", "bar@0.0.2", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "add", "bar@0.0.2"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
diff --git a/test/bun.js/install/bun-install.test.ts b/test/bun.js/install/bun-install.test.ts
index 28a72c4d2..3ea14f27c 100644
--- a/test/bun.js/install/bun-install.test.ts
+++ b/test/bun.js/install/bun-install.test.ts
@@ -1,4 +1,4 @@
-import { file, spawn } from "bun";
+import { file, listen, spawn } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test";
import { bunExe } from "bunExe";
import { bunEnv as env } from "bunEnv";
@@ -22,6 +22,59 @@ afterAll(dummyAfterAll);
beforeEach(dummyBeforeEach);
afterEach(dummyAfterEach);
+it("should report connection errors", async () => {
+ function end(socket) {
+ socket.end();
+ }
+ const server = listen({
+ socket: {
+ data: end,
+ drain: end,
+ open: end,
+ },
+ hostname: "localhost",
+ port: 0,
+ });
+ await writeFile(
+ join(package_dir, "bunfig.toml"),
+ `
+[install]
+cache = false
+registry = "http://localhost:${server.port}/"
+`,
+ );
+ await writeFile(
+ join(package_dir, "package.json"),
+ JSON.stringify({
+ name: "foo",
+ version: "0.0.1",
+ dependencies: {
+ bar: "0.0.2",
+ },
+ }),
+ );
+ 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.split(/\r?\n/)).toContain("error: ConnectionRefused downloading package manifest bar");
+ expect(stdout).toBeDefined();
+ expect(await new Response(stdout).text()).toBe("");
+ expect(await exited).toBe(1);
+ try {
+ await access(join(package_dir, "bun.lockb"));
+ expect(() => {}).toThrow();
+ } catch (err: any) {
+ expect(err.code).toBe("ENOENT");
+ }
+});
+
it("should handle missing package", async () => {
const urls: string[] = [];
setHandler(async request => {
@@ -35,7 +88,7 @@ it("should handle missing package", async () => {
return new Response("bar", { status: 404 });
});
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "foo", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install", "foo"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -78,8 +131,16 @@ it("should handle @scoped authentication", async () => {
urls.push(request.url);
return new Response("Feeling lucky?", { status: 555 });
});
+ // workaround against `writeFile(..., { flag: "a" })`
+ await writeFile(
+ join(package_dir, "bunfig.toml"),
+ `${await file(join(package_dir, "bunfig.toml")).text()}
+[install.scopes]
+foo = { token = "bar" }
+`,
+ );
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "@foo/bar", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install", "@foo/bar"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -117,7 +178,7 @@ it("should handle empty string in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -164,7 +225,7 @@ it("should handle workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -206,7 +267,7 @@ it("should handle workspaces with packages array", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -264,7 +325,7 @@ it("should handle inter-dependency between workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -322,7 +383,7 @@ it("should handle inter-dependency between workspaces (devDependencies)", async
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -380,7 +441,7 @@ it("should handle inter-dependency between workspaces (optionalDependencies)", a
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -430,7 +491,7 @@ it("should ignore peerDependencies within workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -480,7 +541,7 @@ it("should handle life-cycle scripts within workspaces", async () => {
);
await writeFile(join(package_dir, "bar", "index.js"), 'console.log("[scripts:run] Bar");');
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -525,7 +586,7 @@ it("should ignore workspaces within workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -563,7 +624,7 @@ it("should handle ^0 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -606,7 +667,7 @@ it("should handle ^1 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -643,7 +704,7 @@ it("should handle ^0.0 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -686,7 +747,7 @@ it("should handle ^0.1 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -723,7 +784,7 @@ it("should handle ^0.0.0 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -760,7 +821,7 @@ it("should handle ^0.0.2 in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -803,7 +864,7 @@ it("should handle ^0.0.2-rc in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -846,7 +907,7 @@ it("should handle ^0.0.2-alpha.3+b4d in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -903,7 +964,7 @@ it("should prefer latest-tagged dependency", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -959,7 +1020,7 @@ it("should handle dependency aliasing", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1015,7 +1076,7 @@ it("should handle dependency aliasing (versioned)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1071,7 +1132,7 @@ it("should handle dependency aliasing (dist-tagged)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1131,7 +1192,7 @@ it("should not reinstall aliased dependencies", async () => {
stderr: stderr1,
exited: exited1,
} = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1170,7 +1231,7 @@ it("should not reinstall aliased dependencies", async () => {
stderr: stderr2,
exited: exited2,
} = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1237,7 +1298,7 @@ it("should handle aliased & direct dependency references", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1318,7 +1379,7 @@ it("should not hoist if name collides with alias", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1381,7 +1442,7 @@ it("should handle unscoped alias on scoped dependency", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1432,7 +1493,7 @@ it("should handle scoped alias on unscoped dependency", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1482,7 +1543,7 @@ it("should handle GitHub URL in dependencies (user/repo)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1535,7 +1596,7 @@ it("should handle GitHub URL in dependencies (user/repo#commit-id)", async () =>
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1601,7 +1662,7 @@ it("should handle GitHub URL in dependencies (user/repo#tag)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1667,7 +1728,7 @@ it("should handle GitHub URL in dependencies (github:user/repo#tag)", async () =
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1736,7 +1797,7 @@ it("should handle GitHub URL in dependencies (https://github.com/user/repo.git)"
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1789,7 +1850,7 @@ it("should handle GitHub URL in dependencies (git://github.com/user/repo.git#com
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1858,7 +1919,7 @@ it("should handle GitHub URL in dependencies (git+https://github.com/user/repo.g
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -1947,7 +2008,7 @@ it("should consider peerDependencies during hoisting", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml", "--peer"],
+ cmd: [bunExe(), "install", "--peer"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2015,7 +2076,7 @@ it("should not regard peerDependencies declarations as duplicates", async () =>
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2047,7 +2108,7 @@ it("should not regard peerDependencies declarations as duplicates", async () =>
it("should report error on invalid format for package.json", async () => {
await writeFile(join(package_dir, "package.json"), "foo");
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2083,7 +2144,7 @@ it("should report error on invalid format for dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2121,7 +2182,7 @@ it("should report error on invalid format for optionalDependencies", async () =>
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2161,7 +2222,7 @@ it("should report error on invalid format for workspaces", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2215,7 +2276,7 @@ it("should report error on duplicated workspace packages", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2254,7 +2315,7 @@ it("should handle Git URL in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2315,7 +2376,7 @@ it("should handle Git URL in dependencies (SCP-style)", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2376,7 +2437,7 @@ it("should handle Git URL with committish in dependencies", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2439,7 +2500,7 @@ it("should fail on invalid Git URL", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2477,7 +2538,7 @@ it("should fail on Git URL with invalid committish", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2518,7 +2579,7 @@ it("should de-duplicate committish in Git URLs", async () => {
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2612,7 +2673,7 @@ it("should prefer optionalDependencies over dependencies of the same name", asyn
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -2665,7 +2726,7 @@ it("should prefer dependencies over peerDependencies of the same name", async ()
}),
);
const { stdout, stderr, exited } = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
diff --git a/test/bun.js/install/bun-link.test.ts b/test/bun.js/install/bun-link.test.ts
index 88e124ec2..c1e1d1890 100644
--- a/test/bun.js/install/bun-link.test.ts
+++ b/test/bun.js/install/bun-link.test.ts
@@ -278,7 +278,7 @@ it("should link dependency without crashing", async () => {
stderr: stderr2,
exited: exited2,
} = spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
diff --git a/test/bun.js/install/bun-pm.test.ts b/test/bun.js/install/bun-pm.test.ts
index 54bfc534c..3db2a4ad0 100644
--- a/test/bun.js/install/bun-pm.test.ts
+++ b/test/bun.js/install/bun-pm.test.ts
@@ -47,7 +47,7 @@ it("should list top-level dependency", async () => {
);
expect(
await spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -103,7 +103,7 @@ it("should list all dependencies", async () => {
);
expect(
await spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -160,7 +160,7 @@ it("should list top-level aliased dependency", async () => {
);
expect(
await spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
@@ -216,7 +216,7 @@ it("should list aliased dependencies", async () => {
);
expect(
await spawn({
- cmd: [bunExe(), "install", "--config", import.meta.dir + "/basic.toml"],
+ cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
diff --git a/test/bun.js/install/dummy.registry.ts b/test/bun.js/install/dummy.registry.ts
index a0a215db8..d3fdc2d7f 100644
--- a/test/bun.js/install/dummy.registry.ts
+++ b/test/bun.js/install/dummy.registry.ts
@@ -1,6 +1,6 @@
import { file } from "bun";
import { expect } from "bun:test";
-import { mkdtemp, readdir, realpath, rm } from "fs/promises";
+import { mkdtemp, readdir, realpath, rm, writeFile } from "fs/promises";
import { tmpdir } from "os";
import { basename, join } from "path";
@@ -65,9 +65,9 @@ export function dummyBeforeAll() {
requested++;
return await handler(request);
},
- port: 54321,
+ port: 0,
});
- root_url = "http://localhost:54321";
+ root_url = `http://localhost:${server.port}`;
}
export function dummyAfterAll() {
@@ -78,6 +78,14 @@ export async function dummyBeforeEach() {
resetHanlder();
requested = 0;
package_dir = await mkdtemp(join(await realpath(tmpdir()), "bun-install.test"));
+ await writeFile(
+ join(package_dir, "bunfig.toml"),
+ `
+[install]
+cache = false
+registry = "http://localhost:${server.port}/"
+`,
+ );
}
export async function dummyAfterEach() {