setup-bun/tests/registry.spec.ts
Jozef Steinhübl 34f777aec1
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 (#109)
* 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>
2025-07-09 12:22:12 +02:00

170 lines
4.5 KiB
TypeScript

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",
},
]);
});
});
});