Initial Commit
This commit is contained in:
127
packages/localization/i18n/i18n-detector/src/index.test.ts
Normal file
127
packages/localization/i18n/i18n-detector/src/index.test.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import * as root from "./index.js";
|
||||
|
||||
describe("@suaveplan/i18n-detector — root barrel", () => {
|
||||
it("re-exports createDetectorChain", { timeout: 5000 }, () => {
|
||||
expect(typeof root.createDetectorChain).toBe("function");
|
||||
});
|
||||
|
||||
it("re-exports DETECTOR_CHAIN_UNRESOLVED", { timeout: 5000 }, () => {
|
||||
expect(typeof root.DETECTOR_CHAIN_UNRESOLVED).toBe("symbol");
|
||||
});
|
||||
|
||||
it("re-exports bcp47Negotiate", { timeout: 5000 }, () => {
|
||||
expect(typeof root.bcp47Negotiate).toBe("function");
|
||||
});
|
||||
|
||||
it("re-exports getTextDirection and isRtl", { timeout: 5000 }, () => {
|
||||
expect(root.getTextDirection("ar")).toBe("rtl");
|
||||
expect(root.isRtl("en-GB")).toBe(false);
|
||||
});
|
||||
|
||||
it("re-exports every detector factory", { timeout: 5000 }, () => {
|
||||
expect(typeof root.querystringDetector).toBe("function");
|
||||
expect(typeof root.userPreferenceDetector).toBe("function");
|
||||
expect(typeof root.cookieDetector).toBe("function");
|
||||
expect(typeof root.localStorageDetector).toBe("function");
|
||||
expect(typeof root.htmlLangDetector).toBe("function");
|
||||
expect(typeof root.acceptLanguageDetector).toBe("function");
|
||||
expect(typeof root.parseAcceptLanguage).toBe("function");
|
||||
expect(typeof root.navigatorDetector).toBe("function");
|
||||
expect(typeof root.cloudflareIpGeoDetector).toBe("function");
|
||||
expect(typeof root.fallbackDetector).toBe("function");
|
||||
});
|
||||
|
||||
it("re-exports defaultDetectorChain", { timeout: 5000 }, () => {
|
||||
expect(typeof root.defaultDetectorChain).toBe("function");
|
||||
});
|
||||
|
||||
it("re-exports observability helpers", { timeout: 5000 }, () => {
|
||||
expect(typeof root.getDetectorMetrics).toBe("function");
|
||||
expect(typeof root.getDetectorMetricsState).toBe("function");
|
||||
expect(typeof root.resetDetectorMetricsState).toBe("function");
|
||||
expect(typeof root.resetDetectorMetricsCache).toBe("function");
|
||||
expect(typeof root.recordDetectorMatch).toBe("function");
|
||||
expect(typeof root.recordDetectorDuration).toBe("function");
|
||||
expect(typeof root.recordChainExhausted).toBe("function");
|
||||
});
|
||||
});
|
||||
|
||||
describe("@suaveplan/i18n-detector — every documented subpath export resolves", () => {
|
||||
it("subpath barrels resolve through the package", {
|
||||
timeout: 5000,
|
||||
}, async () => {
|
||||
const chain = await import("./chain/index.js");
|
||||
const direction = await import("./direction/index.js");
|
||||
const querystring = await import("./detectors/querystring/index.js");
|
||||
const userPreference = await import(
|
||||
"./detectors/user-preference/index.js"
|
||||
);
|
||||
const cookie = await import("./detectors/cookie/index.js");
|
||||
const localStorage = await import("./detectors/local-storage/index.js");
|
||||
const htmlLang = await import("./detectors/html-lang/index.js");
|
||||
const acceptLanguage = await import(
|
||||
"./detectors/accept-language/index.js"
|
||||
);
|
||||
const navigator = await import("./detectors/navigator/index.js");
|
||||
const cloudflareIpGeo = await import(
|
||||
"./detectors/cloudflare-ip-geo/index.js"
|
||||
);
|
||||
const fallback = await import("./detectors/fallback/index.js");
|
||||
const defaultChain = await import("./default-chain/index.js");
|
||||
|
||||
expect(typeof chain.createDetectorChain).toBe("function");
|
||||
expect(typeof chain.bcp47Negotiate).toBe("function");
|
||||
expect(typeof direction.getTextDirection).toBe("function");
|
||||
expect(typeof querystring.querystringDetector).toBe("function");
|
||||
expect(typeof userPreference.userPreferenceDetector).toBe("function");
|
||||
expect(typeof cookie.cookieDetector).toBe("function");
|
||||
expect(typeof localStorage.localStorageDetector).toBe("function");
|
||||
expect(typeof htmlLang.htmlLangDetector).toBe("function");
|
||||
expect(typeof acceptLanguage.acceptLanguageDetector).toBe("function");
|
||||
expect(typeof acceptLanguage.parseAcceptLanguage).toBe("function");
|
||||
expect(typeof navigator.navigatorDetector).toBe("function");
|
||||
expect(typeof cloudflareIpGeo.cloudflareIpGeoDetector).toBe("function");
|
||||
expect(typeof fallback.fallbackDetector).toBe("function");
|
||||
expect(typeof defaultChain.defaultDetectorChain).toBe("function");
|
||||
});
|
||||
});
|
||||
|
||||
describe("@suaveplan/i18n-detector — package.json", () => {
|
||||
it("declares sideEffects false", { timeout: 5000 }, () => {
|
||||
const pkgUrl = new URL("../package.json", import.meta.url);
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(fileURLToPath(pkgUrl), "utf-8")
|
||||
) as { sideEffects?: boolean };
|
||||
expect(pkg.sideEffects).toBe(false);
|
||||
});
|
||||
|
||||
it("declares every documented subpath export", {
|
||||
timeout: 5000,
|
||||
}, () => {
|
||||
const pkgUrl = new URL("../package.json", import.meta.url);
|
||||
const pkg = JSON.parse(
|
||||
readFileSync(fileURLToPath(pkgUrl), "utf-8")
|
||||
) as { exports?: Record<string, unknown> };
|
||||
const documented = [
|
||||
".",
|
||||
"./chain",
|
||||
"./direction",
|
||||
"./detectors/querystring",
|
||||
"./detectors/user-preference",
|
||||
"./detectors/cookie",
|
||||
"./detectors/local-storage",
|
||||
"./detectors/html-lang",
|
||||
"./detectors/accept-language",
|
||||
"./detectors/navigator",
|
||||
"./detectors/cloudflare-ip-geo",
|
||||
"./detectors/fallback",
|
||||
"./default-chain",
|
||||
];
|
||||
for (const subpath of documented) {
|
||||
expect(pkg.exports?.[subpath]).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user