Files
heroui-vue/tests/package/check-client.mjs
T

121 lines
3.8 KiB
JavaScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import * as lib from "@heroui-vue/components";
const checks = JSON.parse(
readFileSync(new URL("./client-checks.json", import.meta.url), "utf8"),
);
const css = readFileSync(
new URL(import.meta.resolve("@heroui-vue/styles/css")),
"utf8",
);
for (const id of process.argv.slice(2)) {
const spec = checks[id];
assert(spec, `Unknown package contract: ${id}`);
for (const name of spec.exports) assert(lib[name], `Missing export ${name}`);
for (const token of spec.css)
assert(css.includes(token), `Missing CSS ${token}`);
for (const name of spec.absent ?? [])
assert(!(name in lib), `Private component exposed: ${name}`);
if (id === "b02-pickers") {
assert(
lib
.comboBoxVariants({ fullWidth: true })
.base()
.includes("hv-combo-box--full-width"),
);
assert(
lib
.autocompleteVariants({ variant: "secondary" })
.base()
.includes("hv-autocomplete--secondary"),
);
}
if (id === "list-box") {
assert(lib.listboxVariants().includes("hv-list-box"));
assert(
lib
.listboxItemVariants()
.indicator()
.includes("hv-list-box-item__indicator"),
);
}
if (id === "range-calendar") {
assert(lib.RangeCalendar === lib.RangeCalendarRoot);
assert(lib.rangeCalendarVariants().cell() === "hv-range-calendar__cell");
}
if (id === "time-field") {
assert(lib.TimeField === lib.TimeFieldRoot);
assert(lib.TimeFieldGroup === lib.DateInputGroup);
assert(lib.TimeFieldInput === lib.DateInputGroupInput);
assert(
lib
.timeFieldVariants({ fullWidth: true })
.includes("hv-time-field--full-width"),
);
}
if (id === "date-picker") {
assert(lib.DatePicker === lib.DatePickerRoot);
assert(lib.datePickerVariants().base() === "hv-date-picker");
assert(lib.datePickerVariants().trigger() === "hv-date-picker__trigger");
assert(lib.datePickerVariants().popover() === "hv-date-picker__popover");
}
if (id === "slider")
assert(lib.sliderVariants().thumb().includes("hv-slider__thumb"));
if (id === "select")
assert(
lib
.selectVariants({ variant: "secondary" })
.base()
.includes("hv-select--secondary"),
);
if (id === "color-swatch") {
assert(lib.ColorSwatch === lib.ColorSwatchRoot);
assert(
lib
.colorSwatchVariants({ shape: "square", size: "xl" })
.includes("hv-color-swatch--square"),
);
assert(
lib
.colorSwatchVariants({ shape: "square", size: "xl" })
.includes("hv-color-swatch--xl"),
);
assert(lib.parseColor("#f008").toString("hexa") === "#FF000088");
assert(
lib.parseColor("rgba(4, 133, 247, 0.5)").getChannelValue("alpha") === 0.5,
);
const valueDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color/value.d.ts",
import.meta.url,
),
"utf8",
);
const swatchDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-swatch/ColorSwatch.vue.d.ts",
import.meta.url,
),
"utf8",
);
assert(!valueDts.includes("reka-ui"), "Color declarations leak Reka types");
assert(
!swatchDts.includes("reka-ui"),
"ColorSwatch declarations leak Reka types",
);
}
if (id === "b03-tag-error-message") {
assert(/\.hv-tag-group\s*\[data-slot=["']?error-message/.test(css));
assert(lib.tagVariants({ size: "sm" }).base().includes("hv-tag--sm"));
assert(
lib
.tagVariants({ variant: "surface" })
.base()
.includes("hv-tag--surface"),
);
assert(lib.errorMessageVariants().includes("hv-error-message"));
}
console.log(`${id}: packed ESM exports and CSS passed (client scope)`);
}