Skip to content

Documentation

Widget Test Coverage

Comprehensive widget testing documentation for SveltyCMS widget system.

5/6/2026
3 min read Edit on GitHub

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

Related

testingwidgetscoverage
Was this page helpful?