45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { resolveAssetBase } from "./assetCdnBase";
|
|
|
|
describe("resolveAssetBase", () => {
|
|
it("returns '/' when ASSET_CDN_URL is unset", () => {
|
|
expect(resolveAssetBase({}, "production")).toBe("/");
|
|
});
|
|
|
|
it("returns '/' when ASSET_CDN_URL is empty or whitespace", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "" }, "production")).toBe("/");
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: " " }, "production")).toBe("/");
|
|
});
|
|
|
|
it("returns '/' in development regardless of ASSET_CDN_URL (HMR / dev server)", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "https://cdn.example.com" }, "development")).toBe("/");
|
|
});
|
|
|
|
it("returns origin with trailing slash for a valid https URL", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "https://cdn.boiler.saas-ctrl.com" }, "production")).toBe(
|
|
"https://cdn.boiler.saas-ctrl.com/"
|
|
);
|
|
});
|
|
|
|
it("normalises trailing-slash variants to the same value", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "https://cdn.example.com/" }, "production")).toBe(
|
|
"https://cdn.example.com/"
|
|
);
|
|
});
|
|
|
|
it("strips paths from the CDN URL so vite controls the asset subdirectory", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "https://cdn.example.com/some/path" }, "production")).toBe(
|
|
"https://cdn.example.com/"
|
|
);
|
|
});
|
|
|
|
it("falls back to '/' for malformed URLs", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "not-a-url" }, "production")).toBe("/");
|
|
});
|
|
|
|
it("treats an absent mode as non-development", () => {
|
|
expect(resolveAssetBase({ ASSET_CDN_URL: "https://cdn.example.com" })).toBe("https://cdn.example.com/");
|
|
});
|
|
});
|