@continuum-js/test 0.1.0

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.
@@ -0,0 +1,37 @@
1
+ import { type Child } from "@continuum-js/dom";
2
+ /** A mounted view under test. */
3
+ export interface RenderResult {
4
+ /** The container element, attached to `document.body`. */
5
+ container: HTMLElement;
6
+ /** Unmount the view (cascading FRP/ownership cleanup) and drop the container. */
7
+ dispose: () => void;
8
+ }
9
+ /**
10
+ * Mount `view` into a fresh container appended to `document.body` (so focus
11
+ * and event bubbling behave like in a real page). Dispose manually, or let
12
+ * `cleanup()` collect everything at the end of the test.
13
+ */
14
+ export declare function render(view: () => Child): RenderResult;
15
+ /** Dispose every view still mounted by `render`. Call from `afterEach`. */
16
+ export declare function cleanup(): void;
17
+ /** Dispatch `event` on `el`. Returns the `dispatchEvent` result. */
18
+ export declare function fire(el: EventTarget, event: Event): boolean;
19
+ /** Click an element (a bubbling, cancelable MouseEvent). */
20
+ export declare function click(el: EventTarget): boolean;
21
+ /**
22
+ * Type `text` into an input character by character, dispatching a bubbling
23
+ * `input` event after each one — the shape `bindInput` listens to.
24
+ */
25
+ export declare function type(input: HTMLInputElement, text: string): void;
26
+ /**
27
+ * Drain the microtask queue so settled promises (e.g. `perform` results)
28
+ * re-enter the network. Transactions themselves are synchronous — this only
29
+ * waits for the JS runtime, not for Continuum.
30
+ */
31
+ export declare function flush(rounds?: number): Promise<void>;
32
+ /**
33
+ * Advance vitest fake timers by `ms` and flush microtasks, so time-based
34
+ * combinators (`debounce`, `throttle`, `interval`, `delay`) fire and their
35
+ * downstream settles. Requires `vi.useFakeTimers()` in the test.
36
+ */
37
+ export declare function advanceTimers(ms: number): Promise<void>;
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ // Continuum test utilities — render/cleanup, event helpers, async helpers.
2
+ // Framework-agnostic except `advanceTimers`, which integrates with vitest's
3
+ // fake timers (vitest is an optional peer, imported lazily).
4
+ import { mount } from "@continuum-js/dom";
5
+ const live = new Set();
6
+ /**
7
+ * Mount `view` into a fresh container appended to `document.body` (so focus
8
+ * and event bubbling behave like in a real page). Dispose manually, or let
9
+ * `cleanup()` collect everything at the end of the test.
10
+ */
11
+ export function render(view) {
12
+ const container = document.createElement("div");
13
+ document.body.appendChild(container);
14
+ const unmount = mount(container, () => view());
15
+ const dispose = () => {
16
+ live.delete(dispose);
17
+ unmount();
18
+ container.remove();
19
+ };
20
+ live.add(dispose);
21
+ return { container, dispose };
22
+ }
23
+ /** Dispose every view still mounted by `render`. Call from `afterEach`. */
24
+ export function cleanup() {
25
+ for (const dispose of [...live])
26
+ dispose();
27
+ }
28
+ /** Dispatch `event` on `el`. Returns the `dispatchEvent` result. */
29
+ export function fire(el, event) {
30
+ return el.dispatchEvent(event);
31
+ }
32
+ /** Click an element (a bubbling, cancelable MouseEvent). */
33
+ export function click(el) {
34
+ return fire(el, new MouseEvent("click", { bubbles: true, cancelable: true }));
35
+ }
36
+ /**
37
+ * Type `text` into an input character by character, dispatching a bubbling
38
+ * `input` event after each one — the shape `bindInput` listens to.
39
+ */
40
+ export function type(input, text) {
41
+ for (const ch of text) {
42
+ input.value += ch;
43
+ fire(input, new Event("input", { bubbles: true }));
44
+ }
45
+ }
46
+ /**
47
+ * Drain the microtask queue so settled promises (e.g. `perform` results)
48
+ * re-enter the network. Transactions themselves are synchronous — this only
49
+ * waits for the JS runtime, not for Continuum.
50
+ */
51
+ export async function flush(rounds = 3) {
52
+ for (let i = 0; i < rounds; i++)
53
+ await Promise.resolve();
54
+ }
55
+ /**
56
+ * Advance vitest fake timers by `ms` and flush microtasks, so time-based
57
+ * combinators (`debounce`, `throttle`, `interval`, `delay`) fire and their
58
+ * downstream settles. Requires `vi.useFakeTimers()` in the test.
59
+ */
60
+ export async function advanceTimers(ms) {
61
+ const { vi } = await import("vitest");
62
+ await vi.advanceTimersByTimeAsync(ms);
63
+ await flush();
64
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@continuum-js/test",
3
+ "version": "0.1.0",
4
+ "description": "Continuum test utilities — render, event helpers, flush, fake-timer integration",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/denislibs/continuum.git",
9
+ "directory": "packages/test"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "build": "rm -rf dist && tsc -p tsconfig.build.json"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "dependencies": {
33
+ "@continuum-js/dom": "^0.3.0",
34
+ "@continuum-js/frp": "^0.3.0"
35
+ },
36
+ "peerDependencies": {
37
+ "vitest": ">=2"
38
+ },
39
+ "peerDependenciesMeta": {
40
+ "vitest": {
41
+ "optional": true
42
+ }
43
+ }
44
+ }