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

214 lines
6.6 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-range-picker") {
assert(lib.DateRangePicker === lib.DateRangePickerRoot);
assert(lib.dateRangePickerVariants().base() === "hv-date-range-picker");
assert(
lib.dateRangePickerVariants().trigger() ===
"hv-date-range-picker__trigger",
);
assert(
lib.dateRangePickerVariants().rangeSeparator() ===
"hv-date-range-picker__range-separator",
);
assert(
lib.dateRangePickerVariants().popover() ===
"hv-date-range-picker__popover",
);
assert(
lib.dateRangePickerVariants().triggerIndicator() ===
"hv-date-range-picker__trigger-indicator",
);
assert(lib.DateFieldInput);
}
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-area") {
assert(lib.ColorArea === lib.ColorAreaRoot);
assert(lib.ColorAreaThumb);
assert(
lib
.colorAreaVariants({ showDots: true })
.base()
.includes("hv-color-area--show-dots"),
);
assert(
lib.colorAreaVariants().thumb() === "hv-color-area__thumb",
"ColorArea thumb class must stay in the baseline namespace",
);
const areaDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-area/ColorArea.vue.d.ts",
import.meta.url,
),
"utf8",
);
const thumbDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-area/ColorAreaThumb.vue.d.ts",
import.meta.url,
),
"utf8",
);
assert(
!areaDts.includes("reka-ui"),
"ColorArea declarations leak Reka types",
);
assert(
!thumbDts.includes("reka-ui"),
"ColorAreaThumb declarations leak Reka types",
);
}
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 === "color-slider") {
assert(lib.ColorSlider === lib.ColorSliderRoot);
assert(lib.ColorSliderOutput);
assert(lib.ColorSliderTrack);
assert(lib.ColorSliderThumb);
assert(
lib.colorSliderVariants().base() === "hv-color-slider",
"ColorSlider base class must stay in the baseline namespace",
);
assert(
lib.colorSliderVariants().track() === "hv-color-slider__track",
"ColorSlider track class must stay in the baseline namespace",
);
const sliderDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-slider/ColorSlider.vue.d.ts",
import.meta.url,
),
"utf8",
);
const thumbDts = readFileSync(
new URL(
"./node_modules/@heroui-vue/components/dist/components/color-slider/ColorSliderThumb.vue.d.ts",
import.meta.url,
),
"utf8",
);
assert(
!sliderDts.includes("reka-ui"),
"ColorSlider declarations leak Reka types",
);
assert(
!thumbDts.includes("reka-ui"),
"ColorSliderThumb 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)`);
}