diff options
author | 2022-12-26 10:25:59 +0200 | |
---|---|---|
committer | 2022-12-26 00:25:59 -0800 | |
commit | d94b96d9f440d3aeef4402aec9f3788bca2972d0 (patch) | |
tree | 8002c06135f5b247b210b85ef2602cc794f097fd /test | |
parent | 74251fbf5e011191721c96ea520f29a7cc4ea94a (diff) | |
download | bun-d94b96d9f440d3aeef4402aec9f3788bca2972d0.tar.gz bun-d94b96d9f440d3aeef4402aec9f3788bca2972d0.tar.zst bun-d94b96d9f440d3aeef4402aec9f3788bca2972d0.zip |
[install] use specified base URL as default fallback within scopes (#1665)
Diffstat (limited to 'test')
-rw-r--r-- | test/bun.js/bun-install.test.ts | 38 | ||||
-rw-r--r-- | test/bun.js/install/basic.toml (renamed from test/bun.js/bun-install.toml) | 3 | ||||
-rw-r--r-- | test/bun.js/install/bun-install.test.ts | 80 |
3 files changed, 83 insertions, 38 deletions
diff --git a/test/bun.js/bun-install.test.ts b/test/bun.js/bun-install.test.ts deleted file mode 100644 index 1bc4655eb..000000000 --- a/test/bun.js/bun-install.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { spawn, spawnSync } from "bun"; -import { describe, expect, it, test } from "bun:test"; -import { bunExe } from "bunExe"; - -test("bun install", async () => { - const urls = []; - const server = Bun.serve({ - async fetch(request) { - try { - 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(await request.text()).toBe(""); - urls.push(request.url); - return new Response("bar", { status: 404 }); - } finally { - server.stop(); - } - }, - port: 54321, - }); - const { stdout, stderr, exited } = spawn({ - cmd: [bunExe(), "install", "foo", "--config", import.meta.dir + "/bun-install.toml"], - stdout: null, - stdin: "pipe", - stderr: "pipe", - env: { - ...process.env, - BUN_DEBUG_QUIET_LOGS: "1", - }, - }); - expect(stdout).toBeDefined(); - expect(stderr).toBeDefined(); - expect(await new Response(stdout).text()).toBe(""); - var err = await new Response(stderr).text(); - expect(err.split(/\n/)).toContain('error: package "foo" not found localhost/foo 404'); - expect(urls).toContain("http://localhost:54321/foo"); - expect(await exited).toBe(1); -}); diff --git a/test/bun.js/bun-install.toml b/test/bun.js/install/basic.toml index 112c61f86..5007a8efd 100644 --- a/test/bun.js/bun-install.toml +++ b/test/bun.js/install/basic.toml @@ -1,2 +1,5 @@ [install] registry = "http://localhost:54321/" + +[install.scopes] +foo = { token = "bar" }
\ No newline at end of file diff --git a/test/bun.js/install/bun-install.test.ts b/test/bun.js/install/bun-install.test.ts new file mode 100644 index 000000000..8a05ef802 --- /dev/null +++ b/test/bun.js/install/bun-install.test.ts @@ -0,0 +1,80 @@ +import { spawn, spawnSync } from "bun"; +import { describe, expect, it, test } from "bun:test"; +import { bunExe } from "bunExe"; + +test("bun install", async () => { + const urls = []; + const server = Bun.serve({ + async fetch(request) { + try { + 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(await request.text()).toBe(""); + urls.push(request.url); + return new Response("bar", { status: 404 }); + } finally { + server.stop(); + } + }, + port: 54321, + }); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install", "foo", "--config", import.meta.dir + "/basic.toml"], + stdout: null, + stdin: "pipe", + stderr: "pipe", + env: { + ...process.env, + BUN_DEBUG_QUIET_LOGS: "1", + }, + }); + expect(stdout).toBeDefined(); + expect(stderr).toBeDefined(); + expect(await new Response(stdout).text()).toBe(""); + var err = await new Response(stderr).text(); + expect(err.split(/\n/)).toContain('error: package "foo" not found localhost/foo 404'); + expect(urls).toContain("http://localhost:54321/foo"); + expect(await exited).toBe(1); +}); + +test("bun install @scoped", async () => { + let seen_token = false; + const url = "http://localhost:54321/@foo/bar"; + const urls = []; + const server = Bun.serve({ + async fetch(request) { + try { + 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, */*"); + if (request.url === url) { + expect(request.headers.get("authorization")).toBe("Bearer bar"); + seen_token = true; + } + expect(await request.text()).toBe(""); + urls.push(request.url); + return new Response("Tea?", { status: 418 }); + } finally { + server.stop(); + } + }, + port: 54321, + }); + const { stdout, stderr, exited } = spawn({ + cmd: [bunExe(), "install", "@foo/bar", "--config", import.meta.dir + "/basic.toml"], + stdout: null, + stdin: "pipe", + stderr: "pipe", + env: { + ...process.env, + BUN_DEBUG_QUIET_LOGS: "1", + }, + }); + expect(stdout).toBeDefined(); + expect(stderr).toBeDefined(); + expect(await new Response(stdout).text()).toBe(""); + var err = await new Response(stderr).text(); + expect(err.split(/\n/)).toContain(`GET ${url} - 418`); + expect(urls).toContain(url); + expect(seen_token).toBe(true); + expect(await exited).toBe(1); +}); |