mirror of
https://github.com/oven-sh/setup-bun.git
synced 2025-07-18 04:28:28 +02:00
feat: support for multiple registries (#109)
Some checks failed
autofix.ci / format (push) Failing after 1m14s
🧪 Test / remove-cache (push) Successful in 58s
🧪 Test / setup-bun (1.x, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (< 2, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, /foo/package.json (bun@1.1.0)) (push) Failing after 55s
🧪 Test / setup-bun from (ubuntu-latest, package.json (bun@1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, package.json (yarn@bun@1.1.0)) (push) Successful in 58s
🧪 Test / test installing deps from custom registries (ubuntu-latest) (push) Failing after 3m12s
🧪 Test / Tests (push) Successful in 3m13s
🧪 Test / setup-bun (1, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (1.1.0, ubuntu-latest) (push) Successful in 56s
🧪 Test / setup-bun (> 1.0.0, ubuntu-latest) (push) Failing after 1m27s
🧪 Test / setup-bun (canary, ubuntu-latest) (push) Successful in 1m1s
🧪 Test / setup-bun (latest, ubuntu-latest) (push) Successful in 58s
🧪 Test / setup-bun from (ubuntu-latest, .bumrc (1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, .bun-version (1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, download url) (push) Successful in 59s
🧪 Test / setup-bun (latest, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, download url) (push) Has been cancelled
🧪 Test / setup-bun (1, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (latest, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, download url) (push) Has been cancelled
Some checks failed
autofix.ci / format (push) Failing after 1m14s
🧪 Test / remove-cache (push) Successful in 58s
🧪 Test / setup-bun (1.x, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (< 2, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, /foo/package.json (bun@1.1.0)) (push) Failing after 55s
🧪 Test / setup-bun from (ubuntu-latest, package.json (bun@1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, package.json (yarn@bun@1.1.0)) (push) Successful in 58s
🧪 Test / test installing deps from custom registries (ubuntu-latest) (push) Failing after 3m12s
🧪 Test / Tests (push) Successful in 3m13s
🧪 Test / setup-bun (1, ubuntu-latest) (push) Failing after 1m28s
🧪 Test / setup-bun (1.1.0, ubuntu-latest) (push) Successful in 56s
🧪 Test / setup-bun (> 1.0.0, ubuntu-latest) (push) Failing after 1m27s
🧪 Test / setup-bun (canary, ubuntu-latest) (push) Successful in 1m1s
🧪 Test / setup-bun (latest, ubuntu-latest) (push) Successful in 58s
🧪 Test / setup-bun from (ubuntu-latest, .bumrc (1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, .bun-version (1.1.0)) (push) Successful in 57s
🧪 Test / setup-bun from (ubuntu-latest, .tool-versions (bun 1.1.0)) (push) Successful in 56s
🧪 Test / setup-bun from (ubuntu-latest, download url) (push) Successful in 59s
🧪 Test / setup-bun (latest, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, download url) (push) Has been cancelled
🧪 Test / setup-bun (1, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.1.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (1.x, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (< 2, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (> 1.0.0, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, macos-latest) (push) Has been cancelled
🧪 Test / setup-bun (canary, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun (latest, windows-latest) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bumrc (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .bun-version (1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun 1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, .tool-versions (bun1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, /foo/package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (windows-latest, package.json (yarn@bun@1.1.0)) (push) Has been cancelled
🧪 Test / setup-bun from (macos-latest, download url) (push) Has been cancelled
* feat: support for multiple registries * [autofix.ci] apply automated fixes * refactor: drop unnecessary check * fix: pass empty array instead undefined * [autofix.ci] apply automated fixes * fix: dont add registry set line * [autofix.ci] apply automated fixes * feat: few more tests * feat: add bun types * docs: explain registries * feat: save globally * [autofix.ci] apply automated fixes * ci: jsr registry test * ci: add , * ci: test * ci: test * ci: test * ci: test * [autofix.ci] apply automated fixes * feat: use @iarna/toml * [autofix.ci] apply automated fixes * feat: registry parsing * [autofix.ci] apply automated fixes * ci: verbose add * ci: registry install check * ci: registry install check * ci: registry install check * ci: verify registry usage * docs: registries * docs: important block * docs: show table * docs: show table * ci: shell * ci: registry test on linux * ci: registry test on linux * build: text lockfile --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
7c641390eb
commit
34f777aec1
14 changed files with 901 additions and 117 deletions
291
tests/bunfig.spec.ts
Normal file
291
tests/bunfig.spec.ts
Normal file
|
@ -0,0 +1,291 @@
|
|||
import { afterEach, describe, expect, it } from "bun:test";
|
||||
import { existsSync, unlinkSync } from "node:fs";
|
||||
import { writeBunfig } from "../src/bunfig";
|
||||
import { EOL } from "os";
|
||||
|
||||
describe("writeBunfig", () => {
|
||||
const filePath = "bunfig_test.toml";
|
||||
|
||||
async function getFileAndContents() {
|
||||
const file = Bun.file(filePath);
|
||||
const contents = (await file.text()).split(EOL);
|
||||
|
||||
return { file, contents };
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
if (existsSync(filePath)) unlinkSync(filePath);
|
||||
console.log(`${filePath} was deleted`);
|
||||
});
|
||||
|
||||
describe("when no bunfig_test.toml file exists", () => {
|
||||
it("should create a new file with scopes content", async () => {
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "foo-bar",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
'[install.scopes."@foo-bar"]',
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
|
||||
it("should create a new file with global registry", async () => {
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install.registry]",
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
|
||||
it("should create a new file with global registry & token", async () => {
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install.registry]",
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when local bunfig_test.toml file exists", () => {
|
||||
it("and no [install.scopes] exists, should concatenate file correctly", async () => {
|
||||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||
|
||||
await Bun.write(filePath, bunfig);
|
||||
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "foo-bar",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install]",
|
||||
"optional = true",
|
||||
"",
|
||||
" [install.cache]",
|
||||
" disable = true",
|
||||
"",
|
||||
'[install.scopes."@foo-bar"]',
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
|
||||
it("and [install.scopes] exists and it's not the same registry, should concatenate file correctly", async () => {
|
||||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||
|
||||
await Bun.write(filePath, bunfig);
|
||||
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "foo-bar",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install]",
|
||||
"optional = true",
|
||||
"",
|
||||
'[install.scopes."@bla-ble"]',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
'url = "https://npm.pkg.github.com/"',
|
||||
"",
|
||||
'[install.scopes."@foo-bar"]',
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
" [install.cache]",
|
||||
" disable = true",
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
|
||||
it("and [install.scopes] exists and it's the same registry, should concatenate file correctly", async () => {
|
||||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@foo-bar' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||
|
||||
await Bun.write(filePath, bunfig);
|
||||
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "foo-bar",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install]",
|
||||
"optional = true",
|
||||
"",
|
||||
'[install.scopes."@foo-bar"]',
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
'[install.scopes."@bla-ble"]',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
'url = "https://npm.pkg.github.com/"',
|
||||
"",
|
||||
" [install.cache]",
|
||||
" disable = true",
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
|
||||
it("and [install.scopes] and [install] exists, should concantenate file correctly", async () => {
|
||||
const bunfig = `[install]${EOL}optional = true${EOL}${EOL}[install.scopes]${EOL}'@foo-bar' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}'@bla-ble' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/" }${EOL}${EOL}[install.cache]${EOL}disable = true`;
|
||||
|
||||
await Bun.write(filePath, bunfig);
|
||||
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "foo-bar",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
{
|
||||
url: "https://bun.sh",
|
||||
scope: "",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
}, // global registry
|
||||
]);
|
||||
|
||||
const { file, contents } = await getFileAndContents();
|
||||
|
||||
expect(file.exists()).resolves.toBeTrue();
|
||||
|
||||
const expectedContents = [
|
||||
"[install]",
|
||||
"optional = true",
|
||||
"",
|
||||
'[install.scopes."@foo-bar"]',
|
||||
'url = "https://npm.pkg.github.com"',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
'[install.scopes."@bla-ble"]',
|
||||
'token = "$BUN_AUTH_TOKEN"',
|
||||
'url = "https://npm.pkg.github.com/"',
|
||||
"",
|
||||
" [install.cache]",
|
||||
" disable = true",
|
||||
"",
|
||||
" [install.registry]",
|
||||
' url = "https://bun.sh"',
|
||||
' token = "$BUN_AUTH_TOKEN"',
|
||||
"",
|
||||
];
|
||||
|
||||
contents.forEach((content, index) =>
|
||||
expect(content).toBe(expectedContents[index])
|
||||
);
|
||||
|
||||
expect(contents.length).toBe(expectedContents.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when multiple global registries are provided", () => {
|
||||
it("should throw an error", () => {
|
||||
expect(() => {
|
||||
writeBunfig(filePath, [
|
||||
{
|
||||
url: "https://npm.pkg.github.com",
|
||||
scope: "",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
{
|
||||
url: "https://bun.sh",
|
||||
scope: "",
|
||||
token: "$BUN_AUTH_TOKEN",
|
||||
},
|
||||
]);
|
||||
}).toThrow("You can't have more than one global registry.");
|
||||
});
|
||||
});
|
||||
});
|
170
tests/registry.spec.ts
Normal file
170
tests/registry.spec.ts
Normal file
|
@ -0,0 +1,170 @@
|
|||
import { describe, expect, it } from "bun:test";
|
||||
import { parseRegistries } from "../src/registry";
|
||||
|
||||
describe("registry", () => {
|
||||
describe("parseRegistries", () => {
|
||||
it("should return an empty array for empty input", () => {
|
||||
expect(parseRegistries("")).toEqual([]);
|
||||
expect(parseRegistries(" ")).toEqual([]);
|
||||
expect(parseRegistries(null as any)).toEqual([]);
|
||||
expect(parseRegistries(undefined as any)).toEqual([]);
|
||||
});
|
||||
|
||||
it("should parse default registry without token", () => {
|
||||
const input = "https://registry.npmjs.org/";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.npmjs.org/",
|
||||
scope: "",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should parse default registry with token", () => {
|
||||
const input = "https://registry.npmjs.org/|npm_token123";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.npmjs.org/",
|
||||
scope: "",
|
||||
token: "npm_token123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should parse scoped registry with URL credentials", () => {
|
||||
const input = "@myorg:https://username:password@registry.myorg.com/";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://username:password@registry.myorg.com/",
|
||||
scope: "@myorg",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should parse scoped registry with separate token", () => {
|
||||
const input = "@partner:https://registry.partner.com/|token_abc123";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.partner.com/",
|
||||
scope: "@partner",
|
||||
token: "token_abc123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should parse multiple registries", () => {
|
||||
const input = `
|
||||
https://registry.npmjs.org/
|
||||
@myorg:https://username:password@registry.myorg.com/
|
||||
@partner:https://registry.partner.com/|token_abc123
|
||||
`;
|
||||
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.npmjs.org/",
|
||||
scope: "",
|
||||
},
|
||||
{
|
||||
url: "https://username:password@registry.myorg.com/",
|
||||
scope: "@myorg",
|
||||
},
|
||||
{
|
||||
url: "https://registry.partner.com/",
|
||||
scope: "@partner",
|
||||
token: "token_abc123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle scope names without @ prefix", () => {
|
||||
const input = "myorg:https://registry.myorg.com/|token123";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.myorg.com/",
|
||||
scope: "myorg",
|
||||
token: "token123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should throw error for invalid URLs", () => {
|
||||
expect(() => {
|
||||
parseRegistries("@myorg:not-a-valid-url");
|
||||
}).toThrow("Invalid URL in registry configuration: not-a-valid-url");
|
||||
|
||||
expect(() => {
|
||||
parseRegistries("also-not-a-valid-url");
|
||||
}).toThrow("Invalid URL in registry configuration: also-not-a-valid-url");
|
||||
});
|
||||
|
||||
it("should handle whitespace and empty lines", () => {
|
||||
const input = `
|
||||
|
||||
https://registry.npmjs.org/
|
||||
|
||||
@myorg:https://registry.myorg.com/|token123
|
||||
|
||||
`;
|
||||
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.npmjs.org/",
|
||||
scope: "",
|
||||
},
|
||||
{
|
||||
url: "https://registry.myorg.com/",
|
||||
scope: "@myorg",
|
||||
token: "token123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle URLs with paths and query parameters", () => {
|
||||
const input =
|
||||
"@myorg:https://registry.myorg.com/npm/registry/?timeout=5000|token123";
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.myorg.com/npm/registry/?timeout=5000",
|
||||
scope: "@myorg",
|
||||
token: "token123",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should correctly handle scopes with hyphens and underscores", () => {
|
||||
const input = `
|
||||
@my-org:https://registry.myorg.com/
|
||||
@my_org:https://registry.myorg.com/
|
||||
`;
|
||||
|
||||
const result = parseRegistries(input);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
url: "https://registry.myorg.com/",
|
||||
scope: "@my-org",
|
||||
},
|
||||
{
|
||||
url: "https://registry.myorg.com/",
|
||||
scope: "@my_org",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
8
tests/tsconfig.json
Normal file
8
tests/tsconfig.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"types": [
|
||||
"bun"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue