Widget Test Coverage
Comprehensive widget testing documentation for SveltyCMS widget system.
On this page
Executive Summary
SveltyCMS has achieved 100% Unit Test Coverage for all core widgets. The testing architecture has transitioned to a modular, portable pattern that supports both high-performance core verification and isolated marketplace widget testing.
Test Statistics
| Category | Test Files | Status | Coverage |
|---|---|---|---|
| Core Widgets | 12 | โ 100% Pass | Validation, Defaults, Aggregations, i18n |
| Custom Widgets | 3+ | โ 100% Pass | Portable tests (Address, Price, Repeater) |
| Widget System | 2 | โ 100% Pass | Factory Pattern, Validation Utils |
| Total | 17+ | โ Passed | Vitest Compatibility |
๐๏ธ New Testing Architecture
Following the May 2026 Stabilization, the widget testing suite is organized into two primary categories:
1. Core Widget Tests (tests/unit/widgets/core/)
Core widgets are the backbone of the CMS. Each widget now has a dedicated test file ensuring zero regressions in data contracts and validation schemas.
- โ
checkbox.test.ts - โ
date-time.test.ts - โ
email.test.ts - โ
group.test.ts - โ
input.test.ts - โ
media-upload.test.ts - โ
number.test.ts - โ
radio.test.ts - โ
relation.test.ts - โ
rich-text.test.ts - โ
select.test.ts - โ
slug.test.ts
2. Portable Custom Widgets (src/widgets/custom/[name]/tests/)
Inspired by the Drupal Module Pattern, custom widgets are now self-contained. Their tests live inside the widget folder, making them fully portable and marketplace-ready.
- โ
address/tests/address.test.ts - โ
price/tests/price.test.ts - โ
repeater/tests/repeater.test.ts
๐งช Testing Patterns
Validation Schema Testing (Black-Box)
We test widgets without mounting Svelte components to keep the CI pipeline extremely fast. We validate the validationSchema returned by the createWidget factory.
import { safeParse } from "valibot";
import EmailWidget from "@widgets/core/email";
test("Email Widget Validation", () => {
const field = EmailWidget({ label: "Email", required: true });
const schema = (field.widget.validationSchema as any)(field);
expect(safeParse(schema, "test@example.com").success).toBe(true);
expect(safeParse(schema, "invalid-email").success).toBe(false);
});
```
### Multilingual Support
Tests verify that translated fields correctly handle `Record<string, string>` structures versus primitive values.
### Database Aggregations
Verified via unit tests ensuring that `filters` and `sorts` return valid MongoDB/SQL-compatible query fragments.
---
## ๐ Execution Guide
### Run All Widget Tests (Bun)
```
bun run test:unit
```
### Run Specific Core Test
```
bun test tests/unit/widgets/core/input.test.ts
```
### Run Portable Custom Test
```
bun test src/widgets/custom/address/tests/address.test.ts
```
---
## Status Report
- โ
**Core Logic Coverage**: 100%
- โ
**Schema Validation**: 100%
- โ
**Portable Pattern**: Fully Implemented
- โ
**Bun Runner Stability**: Verified