@rokkit/helpers 1.0.0-next.132 → 1.0.0-next.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Jerry Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # @rokkit/helpers
2
+
3
+ Test utilities for Rokkit — custom Vitest matchers, DOM mocks, and touch/mouse event simulators.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add -D @rokkit/helpers
9
+ # or
10
+ npm install --save-dev @rokkit/helpers
11
+ ```
12
+
13
+ This package is for testing only. Add it to `devDependencies`.
14
+
15
+ ## Overview
16
+
17
+ `@rokkit/helpers` provides four subpath imports:
18
+
19
+ | Import | Contents |
20
+ | ---------------------------- | --------------------------------------------------------------- |
21
+ | `@rokkit/helpers/matchers` | Custom Vitest matchers for dataset, actions, events, and arrays |
22
+ | `@rokkit/helpers/mocks` | DOM mocks auto-installed into the global scope for jsdom |
23
+ | `@rokkit/helpers/simulators` | Touch and mouse event simulators |
24
+ | `@rokkit/helpers/components` | Minimal Svelte test components |
25
+
26
+ ## Setup
27
+
28
+ Register the mocks and matchers in a Vitest setup file:
29
+
30
+ ```js
31
+ // vitest.config.js
32
+ import { defineConfig } from 'vitest/config'
33
+ import { svelte } from '@sveltejs/vite-plugin-svelte'
34
+
35
+ export default defineConfig({
36
+ plugins: [svelte({ hot: false })],
37
+ test: {
38
+ environment: 'jsdom',
39
+ setupFiles: ['./test-setup.js']
40
+ }
41
+ })
42
+ ```
43
+
44
+ ```js
45
+ // test-setup.js
46
+ import { expect } from 'vitest'
47
+ import { matchers } from '@rokkit/helpers/matchers'
48
+ import '@rokkit/helpers/mocks' // installs ResizeObserver, IntersectionObserver, etc.
49
+
50
+ expect.extend(matchers)
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ ### Custom matchers
56
+
57
+ ```js
58
+ import { render } from '@testing-library/svelte'
59
+ import MyComponent from './MyComponent.svelte'
60
+
61
+ test('renders with correct data attribute', async () => {
62
+ const { getByRole } = render(MyComponent, { props: { value: 'active' } })
63
+ const el = getByRole('listitem')
64
+
65
+ // Assert a single data-* attribute
66
+ expect(el).toHaveDataset('value', 'active')
67
+
68
+ // Assert all data attributes at once
69
+ expect(el).toHaveValidData({ value: 'active', index: '0' })
70
+ })
71
+ ```
72
+
73
+ ```js
74
+ import { toHaveAction } from '@rokkit/helpers/matchers'
75
+
76
+ test('action is applied to element', () => {
77
+ // toHaveAction checks that a Svelte action registered its event listeners
78
+ expect(el).toHaveAction('navigate')
79
+ })
80
+ ```
81
+
82
+ ### DOM mocks
83
+
84
+ Importing `@rokkit/helpers/mocks` installs the following globals automatically:
85
+
86
+ - `ResizeObserver` — records observed elements; no-op callbacks
87
+ - `IntersectionObserver` — records observed elements; no-op callbacks
88
+ - `requestAnimationFrame` / `cancelAnimationFrame` — synchronous shims
89
+ - `matchMedia` — returns a configurable mock
90
+
91
+ ```js
92
+ import { setMatchMedia } from '@rokkit/helpers/mocks'
93
+
94
+ test('responds to dark mode', () => {
95
+ setMatchMedia({ matches: true })
96
+ // ... render component and assert
97
+ })
98
+ ```
99
+
100
+ ### Event simulators
101
+
102
+ ```js
103
+ import { simulateTouchSwipe, simulateMouseSwipe } from '@rokkit/helpers/simulators'
104
+
105
+ test('swipe left triggers dismiss', async () => {
106
+ const el = document.querySelector('.card')
107
+
108
+ // simulateTouchSwipe(element, distancePx, delayMs)
109
+ await simulateTouchSwipe(el, -150, 50)
110
+
111
+ expect(el).not.toBeInTheDocument()
112
+ })
113
+ ```
114
+
115
+ ```js
116
+ import { simulateTouchEvent, simulateMouseEvent } from '@rokkit/helpers/simulators'
117
+
118
+ // Low-level control
119
+ simulateTouchEvent(el, 0, 0, 'touchstart')
120
+ simulateTouchEvent(el, 80, 0, 'touchmove')
121
+ simulateTouchEvent(el, 80, 0, 'touchend')
122
+ ```
123
+
124
+ ## API
125
+
126
+ ### `@rokkit/helpers/matchers`
127
+
128
+ | Matcher | Description |
129
+ | ---------------------------- | --------------------------------------------------- |
130
+ | `toHaveDataset(key, value)` | Assert a single `data-*` attribute |
131
+ | `toHaveValidData(object)` | Assert all dataset attributes match an object |
132
+ | `toHaveAction(actionName)` | Assert a Svelte action registered its listeners |
133
+ | `toDispatchEvent(eventName)` | Assert a custom DOM event was dispatched |
134
+ | `toBeArrayOf(type)` | Assert every element in an array is of a given type |
135
+
136
+ ### `@rokkit/helpers/mocks`
137
+
138
+ | Export | Description |
139
+ | ------------------------------- | ------------------------------------------------------- |
140
+ | `ResizeObserver` | ResizeObserver mock (auto-installed globally on import) |
141
+ | `IntersectionObserver` | IntersectionObserver mock (auto-installed globally) |
142
+ | `setMatchMedia(options)` | Configure the matchMedia mock |
143
+ | `elementsWithSize(count, size)` | Create element stubs with a fixed `offsetHeight` |
144
+
145
+ ### `@rokkit/helpers/simulators`
146
+
147
+ | Export | Description |
148
+ | ----------------------------------------- | ----------------------------------------------- |
149
+ | `simulateTouchEvent(el, x, y, type)` | Fire a single touch event |
150
+ | `simulateMouseEvent(el, x, y, type)` | Fire a single mouse event |
151
+ | `simulateTouchSwipe(el, distance, delay)` | Fire touchstart → touchmove → touchend sequence |
152
+ | `simulateMouseSwipe(el, distance, delay)` | Fire mousedown → mousemove → mouseup sequence |
153
+
154
+ ## Peer Dependencies
155
+
156
+ - `vitest` >= 2.0
157
+
158
+ ---
159
+
160
+ Part of [Rokkit](https://github.com/jerrythomas/rokkit) — a Svelte 5 component library and design system.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/helpers",
3
- "version": "1.0.0-next.132",
3
+ "version": "1.0.0-next.134",
4
4
  "description": "Custom matchers for vitest, mocks and simulators for testing.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,8 @@
19
19
  "src/**/*.svelte",
20
20
  "dist/**/*.d.ts",
21
21
  "README.md",
22
- "package.json"
22
+ "package.json",
23
+ "LICENSE"
23
24
  ],
24
25
  "exports": {
25
26
  "./package.json": "./package.json",
@@ -34,7 +35,8 @@
34
35
  }
35
36
  },
36
37
  "scripts": {
37
- "prepublishOnly": "tsc --project tsconfig.build.json",
38
+ "prepublishOnly": "cp ../../LICENSE . && tsc --project tsconfig.build.json",
39
+ "postpublish": "rm -f LICENSE",
38
40
  "clean": "rm -rf dist",
39
41
  "build": "bun clean && bun prepublishOnly"
40
42
  },
@@ -86,7 +86,6 @@ export function createNestedElement(item) {
86
86
  * Mocks the requestSubmit function for HTMLFormElement which is not implemented by JSDOM
87
87
  */
88
88
  export function mockFormRequestSubmit() {
89
-
90
89
  HTMLFormElement.prototype.requestSubmit = vi.fn(function (submitter) {
91
90
  const event = new Event('submit', {
92
91
  bubbles: true,
@@ -14,4 +14,3 @@ global.IntersectionObserver = IntersectionObserver
14
14
  if (typeof document !== 'undefined' && !document.execCommand) {
15
15
  document.execCommand = () => false
16
16
  }
17
-