@krate/runtime 0.4.0-rc.3 → 0.4.0-rc.5

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,130 @@
1
+ import { describe, it, expect, beforeAll } from 'vitest';
2
+ class FakeEventSource {
3
+ constructor(url) {
4
+ this.url = url;
5
+ this.listeners = {};
6
+ FakeEventSource.last = this;
7
+ }
8
+ addEventListener(type, fn) {
9
+ var _a;
10
+ ((_a = this.listeners)[type] || (_a[type] = [])).push(fn);
11
+ }
12
+ emit(type, data) {
13
+ for (const fn of this.listeners[type] || [])
14
+ fn({ data: JSON.stringify(data) });
15
+ }
16
+ }
17
+ FakeEventSource.last = null;
18
+ let overlay;
19
+ // File-level setup: globals must exist BEFORE the overlay module auto-inits on
20
+ // import, and the export is captured from the same module instance.
21
+ beforeAll(async () => {
22
+ globalThis.EventSource = FakeEventSource;
23
+ window.__KRATE_DEV__ = {
24
+ sse: '/__krate/hotreload',
25
+ errors: '/__krate/client-error',
26
+ open: '/__krate/open',
27
+ overlay: true,
28
+ toolbar: true,
29
+ };
30
+ overlay = await import('./dev-overlay');
31
+ });
32
+ function devRoot() {
33
+ const host = document.getElementById('krate-dev-root');
34
+ return host ? host.shadowRoot : null;
35
+ }
36
+ describe('dev-overlay', () => {
37
+ it('mounts a shadow-root host with a toolbar', () => {
38
+ const shadow = devRoot();
39
+ expect(shadow).toBeTruthy();
40
+ expect(shadow.querySelector('.toolbar')).toBeTruthy();
41
+ expect(shadow.querySelector('.overlay')).toBeTruthy();
42
+ });
43
+ it('renders structured build diagnostics with location, frame and hint', () => {
44
+ FakeEventSource.last.emit('build-error', {
45
+ diagnostics: [
46
+ {
47
+ file: 'a.tsx',
48
+ line: 3,
49
+ col: 5,
50
+ message: 'boom',
51
+ hint: 'fix it',
52
+ source: 'const x = 1;',
53
+ },
54
+ ],
55
+ buildOk: false,
56
+ });
57
+ const overlay = devRoot().querySelector('.overlay');
58
+ expect(overlay.hidden).toBe(false);
59
+ const text = devRoot().querySelector('.list').textContent || '';
60
+ expect(text).toContain('boom');
61
+ expect(text).toContain('a.tsx:3:5');
62
+ expect(text).toContain('fix it');
63
+ expect(text).toContain('^');
64
+ const open = devRoot().querySelector('.open');
65
+ expect(open).toBeTruthy();
66
+ expect(open.textContent).toContain('Open in editor');
67
+ });
68
+ it('updates the toolbar route on SPA (history) navigation', () => {
69
+ history.pushState({}, '', '/some/other/route');
70
+ const route = devRoot().querySelector('.route');
71
+ expect(route.textContent).toBe('/some/other/route');
72
+ });
73
+ it('shows runtime errors from client-error events', () => {
74
+ FakeEventSource.last.emit('client-error', {
75
+ clientError: { message: 'kaboom', stack: 'at foo (a.tsx:1:1)' },
76
+ });
77
+ const text = devRoot().querySelector('.list').textContent || '';
78
+ expect(text).toContain('kaboom');
79
+ });
80
+ it('hides the overlay on Escape', () => {
81
+ document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
82
+ const overlay = devRoot().querySelector('.overlay');
83
+ expect(overlay.hidden).toBe(true);
84
+ });
85
+ });
86
+ describe('routeMatches', () => {
87
+ it('matches unprefixed patterns against a base-path URL', () => {
88
+ expect(overlay.routeMatches('/about', '/docs/about', '/docs')).toBe(true);
89
+ expect(overlay.routeMatches('/about', '/docs/other', '/docs')).toBe(false);
90
+ expect(overlay.routeMatches('/', '/docs/', '/docs')).toBe(true);
91
+ });
92
+ it('matches root deployment and dynamic segments', () => {
93
+ expect(overlay.routeMatches('/about', '/about', '')).toBe(true);
94
+ expect(overlay.routeMatches('/blog/[slug]', '/blog/hello', '')).toBe(true);
95
+ expect(overlay.routeMatches('/blog/[slug]', '/blog/hello/x', '')).toBe(false);
96
+ expect(overlay.routeMatches('/docs/[...rest]', '/docs/a/b/c', '')).toBe(true);
97
+ });
98
+ });
99
+ describe('source-map symbolication', () => {
100
+ it('decodes Base64 VLQ deltas', () => {
101
+ expect(overlay.decodeVLQ('AAAA')).toEqual([0, 0, 0, 0]);
102
+ expect(overlay.decodeVLQ('CAAA')).toEqual([1, 0, 0, 0]);
103
+ });
104
+ it('decodes mappings with cumulative source line deltas', () => {
105
+ const lines = overlay.decodeMappings('AAAA;AACA');
106
+ expect(lines).toHaveLength(2);
107
+ expect(lines[0][0]).toMatchObject({ genCol: 0, src: 0, srcLine: 0, srcCol: 0 });
108
+ expect(lines[1][0]).toMatchObject({ genCol: 0, src: 0, srcLine: 1, srcCol: 0 });
109
+ });
110
+ it('parses V8 and path-only stack frames', () => {
111
+ const a = overlay.parseStackFrame(' at foo (http://localhost:3000/index.abc.js:12:34)');
112
+ expect(a).toMatchObject({ url: 'http://localhost:3000/index.abc.js', line: 12, col: 34 });
113
+ const b = overlay.parseStackFrame(' at bar (/index.abc.js:5:6)');
114
+ expect(b).toMatchObject({ url: '/index.abc.js', line: 5, col: 6 });
115
+ expect(overlay.parseStackFrame('plain message')).toBeNull();
116
+ });
117
+ it('remaps a frame using a fetched map', async () => {
118
+ globalThis.fetch = async () => ({
119
+ ok: true,
120
+ json: async () => ({ version: 3, sources: ['src/foo.ts'], mappings: 'AAAA;AACA' }),
121
+ });
122
+ const out = await overlay.symbolicateStack('Error: x\n at foo (http://localhost:3000/index.abc.js:2:1)');
123
+ expect(out).toContain('src/foo.ts:2:1');
124
+ });
125
+ it('leaves the stack unchanged when no map is available', async () => {
126
+ globalThis.fetch = async () => ({ ok: false, json: async () => ({}) });
127
+ const stack = ' at foo (http://localhost:3000/missing.js:1:1)';
128
+ expect(await overlay.symbolicateStack(stack)).toBe(stack);
129
+ });
130
+ });
package/dist/dom.js CHANGED
@@ -7,7 +7,7 @@ const EVENT_ALIASES = {
7
7
  blur: 'focusout',
8
8
  change: 'input',
9
9
  };
10
- // ─── per-node effect tracking ────────────────────────────────────────────────
10
+ // per-node effect tracking
11
11
  // Reactive props/children create effects that must be disposed when the node is
12
12
  // removed from the DOM (list items, conditional branches, SPA reconciliation).
13
13
  // Without this, effects and their closures accumulate for the page's lifetime.
@@ -32,7 +32,7 @@ export function disposeNode(node) {
32
32
  disposeNode(node.childNodes[i]);
33
33
  }
34
34
  }
35
- // ─── comment-marker DOM traversal ───────────────────────────────────────────
35
+ // comment-marker DOM traversal
36
36
  /**
37
37
  * Find the matching end comment marker for a start marker.
38
38
  * Searches forward among SIBLINGS ONLY (same parent/depth) for the next
@@ -82,7 +82,7 @@ export function insert(parent, value, startMarker) {
82
82
  insertBefore(parent, value, endMarker);
83
83
  }
84
84
  else {
85
- // No end marker found — append at end
85
+ // No end marker found - append at end
86
86
  insertBefore(parent, value, null);
87
87
  }
88
88
  }
@@ -214,11 +214,11 @@ export function mount(fn, container) {
214
214
  export function hydrate(fn, container) {
215
215
  const el = getContainer(container);
216
216
  if (el.childNodes.length === 0) {
217
- // Empty container — fall back to mount behavior
217
+ // Empty container - fall back to mount behavior
218
218
  el.appendChild(fn());
219
219
  return;
220
220
  }
221
- // SSR content exists — run the component to set up effects/signals.
221
+ // SSR content exists - run the component to set up effects/signals.
222
222
  // The freshly-built tree is only used to establish reactive subscriptions;
223
223
  // it is not attached to the DOM, so dispose its effects to avoid leaks.
224
224
  const tree = fn();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dev Error Overlay — shows a styled error overlay in development mode.
2
+ * Dev Error Overlay - shows a styled error overlay in development mode.
3
3
  * Catches unhandled errors and unhandled promise rejections,
4
4
  * displays them in a dismissable overlay with file/line info.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dev Error Overlay — shows a styled error overlay in development mode.
2
+ * Dev Error Overlay - shows a styled error overlay in development mode.
3
3
  * Catches unhandled errors and unhandled promise rejections,
4
4
  * displays them in a dismissable overlay with file/line info.
5
5
  */
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  export { createSignal, createReducer, createCSSChoice, createCSSToggle, createCSSFlags, createCSSGroup, createCSSRange, createCSSStack, createEffect, createMemo, onCleanup, onMount, forwardRef, useRef, disposeAll } from './signal.js';
2
- export type { CSSARIAOptions, CSSVars, CSSPrimitiveOptions, CSSStackActions, SignalOptions } from './signal.js';
2
+ export type { CSSARIAOptions, CSSVars, CSSPrimitiveOptions, CSSStackActions, CSSScope, CSSFlagsScope, SignalOptions } from './signal.js';
3
3
  export { clearPersisted, readPersisted, writePersisted } from './storage.js';
4
4
  export type { PersistOptions, PersistSpec, PersistStore, StorageLike } from './storage.js';
5
5
  export { h, mount, hydrate, insert, clearNodes, disposeNode } from './dom.js';
6
6
  export { Fragment, jsx, jsxs } from './jsx-runtime.js';
7
- export { initRouter, reinitRouter } from './router.js';
7
+ export { initRouter, reinitRouter, navigate } from './router.js';
8
+ export type { NavigateOptions } from './router.js';
8
9
  export { clsx, cn, cva, twMerge, Slot, cloneElement } from './class-helpers.js';
9
10
  export type { ClassValue, CVAConfig } from './class-helpers.js';
10
- export { createContext, resetContexts } from './context.js';
11
+ export { createContext, createScope, createScopeFlags, resetContexts } from './context.js';
11
12
  export { createResource } from './resource.js';
12
13
  export type { Context } from './context.js';
13
14
  export type { ResourceReturn, ResourceActions } from './resource.js';
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ export { createSignal, createReducer, createCSSChoice, createCSSToggle, createCS
2
2
  export { clearPersisted, readPersisted, writePersisted } from './storage.js';
3
3
  export { h, mount, hydrate, insert, clearNodes, disposeNode } from './dom.js';
4
4
  export { Fragment, jsx, jsxs } from './jsx-runtime.js';
5
- export { initRouter, reinitRouter } from './router.js';
5
+ export { initRouter, reinitRouter, navigate } from './router.js';
6
6
  export { clsx, cn, cva, twMerge, Slot, cloneElement } from './class-helpers.js';
7
- export { createContext, resetContexts } from './context.js';
7
+ export { createContext, createScope, createScopeFlags, resetContexts } from './context.js';
8
8
  export { createResource } from './resource.js';
9
9
  import './jsx-types.js';
10
10
  import './css-modules.js';