@useavalon/avalon 0.1.4 → 0.1.6

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.
Files changed (32) hide show
  1. package/package.json +31 -58
  2. package/src/vite-plugin/plugin.ts +22 -4
  3. package/src/build/README.md +0 -310
  4. package/src/client/tests/css-hmr-handler.test.ts +0 -360
  5. package/src/client/tests/framework-adapter.test.ts +0 -519
  6. package/src/client/tests/hmr-coordinator.test.ts +0 -176
  7. package/src/client/tests/hydration-option-parsing.test.ts +0 -107
  8. package/src/client/tests/lit-adapter.test.ts +0 -427
  9. package/src/client/tests/preact-adapter.test.ts +0 -353
  10. package/src/client/tests/qwik-adapter.test.ts +0 -343
  11. package/src/client/tests/react-adapter.test.ts +0 -317
  12. package/src/client/tests/solid-adapter.test.ts +0 -396
  13. package/src/client/tests/svelte-adapter.test.ts +0 -387
  14. package/src/client/tests/vue-adapter.test.ts +0 -407
  15. package/src/components/tests/component-analyzer.test.ts +0 -96
  16. package/src/components/tests/component-detection.test.ts +0 -347
  17. package/src/components/tests/persistent-islands.test.ts +0 -398
  18. package/src/core/components/tests/enhanced-framework-detector.test.ts +0 -577
  19. package/src/core/components/tests/framework-registry.test.ts +0 -465
  20. package/src/core/integrations/README.md +0 -282
  21. package/src/core/layout/tests/enhanced-layout-resolver.test.ts +0 -477
  22. package/src/core/layout/tests/layout-cache-optimization.test.ts +0 -149
  23. package/src/core/layout/tests/layout-composer.test.ts +0 -486
  24. package/src/core/layout/tests/layout-data-loader.test.ts +0 -443
  25. package/src/core/layout/tests/layout-discovery.test.ts +0 -253
  26. package/src/core/layout/tests/layout-matcher.test.ts +0 -480
  27. package/src/core/modules/tests/framework-module-resolver.test.ts +0 -263
  28. package/src/core/modules/tests/module-resolution-integration.test.ts +0 -117
  29. package/src/islands/discovery/tests/island-discovery.test.ts +0 -881
  30. package/src/middleware/__tests__/discovery.test.ts +0 -107
  31. package/src/types/tests/layout-types.test.ts +0 -197
  32. package/src/vite-plugin/tests/image-optimization.test.ts +0 -54
@@ -1,360 +0,0 @@
1
- /**
2
- * Tests for CSS HMR Handler
3
- */
4
-
5
- import { describe, it, expect } from 'vitest';
6
- import { CSSHMRHandler, getCSSHMRHandler } from '../css-hmr-handler.ts';
7
- import type { Update } from '../hmr-coordinator.ts';
8
-
9
- // Mock DOM environment for testing
10
- class MockDocument {
11
- private listeners: Map<string, Array<(event: Event) => void>> = new Map();
12
- private elements: MockHTMLElement[] = [];
13
- head: { appendChild: (el: any) => void; querySelector: (selector: string) => any } = {
14
- appendChild: () => {},
15
- querySelector: () => null,
16
- };
17
-
18
- addEventListener(event: string, callback: (event: Event) => void): void {
19
- if (!this.listeners.has(event)) {
20
- this.listeners.set(event, []);
21
- }
22
- this.listeners.get(event)!.push(callback);
23
- }
24
-
25
- dispatchEvent(event: Event): void {
26
- const callbacks = this.listeners.get(event.type) || [];
27
- for (const callback of callbacks) {
28
- callback(event);
29
- }
30
- }
31
-
32
- querySelector<T extends Element>(selector: string): T | null {
33
- return null;
34
- }
35
-
36
- querySelectorAll<T extends Element>(selector: string): T[] {
37
- const filtered = this.elements.filter(el => {
38
- if (selector === '[data-src]') {
39
- return el.hasAttribute('data-src');
40
- }
41
- return false;
42
- });
43
- return filtered as unknown as T[];
44
- }
45
-
46
- addElement(element: MockHTMLElement): void {
47
- this.elements.push(element);
48
- }
49
-
50
- clearElements(): void {
51
- this.elements = [];
52
- }
53
-
54
- clearListeners(): void {
55
- this.listeners.clear();
56
- }
57
- }
58
-
59
- class MockHTMLElement {
60
- private attributes: Map<string, string> = new Map();
61
- private listeners: Map<string, Array<(event: Event) => void>> = new Map();
62
-
63
- getAttribute(name: string): string | null {
64
- return this.attributes.get(name) || null;
65
- }
66
-
67
- setAttribute(name: string, value: string): void {
68
- this.attributes.set(name, value);
69
- }
70
-
71
- removeAttribute(name: string): void {
72
- this.attributes.delete(name);
73
- }
74
-
75
- hasAttribute(name: string): boolean {
76
- return this.attributes.has(name);
77
- }
78
-
79
- addEventListener(event: string, callback: (event: Event) => void): void {
80
- if (!this.listeners.has(event)) {
81
- this.listeners.set(event, []);
82
- }
83
- this.listeners.get(event)!.push(callback);
84
- }
85
-
86
- dispatchEvent(event: Event): void {
87
- const callbacks = this.listeners.get(event.type) || [];
88
- for (const callback of callbacks) {
89
- callback(event);
90
- }
91
- }
92
- }
93
-
94
- class MockCustomEvent extends Event {
95
- detail: any;
96
-
97
- constructor(type: string, options?: { detail?: any; bubbles?: boolean }) {
98
- super(type, options);
99
- this.detail = options?.detail;
100
- }
101
- }
102
-
103
- // Setup mock global document
104
- const mockDocument = new MockDocument();
105
- (globalThis as any).document = mockDocument;
106
- (globalThis as any).CustomEvent = MockCustomEvent;
107
-
108
- describe('CSSHMRHandler - Global CSS Updates', () => {
109
- it('should handle global CSS update', async () => {
110
- mockDocument.clearListeners();
111
-
112
- const handler = new CSSHMRHandler();
113
- const update: Update = {
114
- type: 'css-update',
115
- path: '/src/styles/global.css',
116
- acceptedPath: '/src/styles/global.css',
117
- timestamp: Date.now(),
118
- };
119
-
120
- let eventFired = false;
121
- let eventDetail: any = null;
122
- mockDocument.addEventListener('css-hmr-update', (e: Event) => {
123
- const customEvent = e as MockCustomEvent;
124
- eventFired = true;
125
- eventDetail = customEvent.detail;
126
- });
127
-
128
- await handler.handleCSSUpdate(update);
129
-
130
- expect(eventFired).toBe(true);
131
- expect(eventDetail.type).toBe('global');
132
- expect(eventDetail.success).toBe(true);
133
- handler.clearCache();
134
- });
135
- });
136
-
137
- describe('CSSHMRHandler - CSS Module Updates', () => {
138
- it('should identify CSS module updates', async () => {
139
- mockDocument.clearListeners();
140
- mockDocument.clearElements();
141
-
142
- // Add an island so the event fires
143
- const mockIsland = new MockHTMLElement();
144
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.tsx');
145
- mockDocument.addElement(mockIsland);
146
-
147
- const handler = new CSSHMRHandler();
148
- const update: Update = {
149
- type: 'css-update',
150
- path: '/src/islands/TestComponent.module.css',
151
- acceptedPath: '/src/islands/TestComponent.module.css',
152
- timestamp: Date.now(),
153
- };
154
-
155
- let eventFired = false;
156
- let eventDetail: any = null;
157
- mockDocument.addEventListener('css-hmr-update', (e: Event) => {
158
- const customEvent = e as MockCustomEvent;
159
- eventFired = true;
160
- eventDetail = customEvent.detail;
161
- });
162
-
163
- await handler.handleCSSUpdate(update);
164
-
165
- expect(eventFired).toBe(true);
166
- expect(eventDetail.type).toBe('module');
167
- handler.clearCache();
168
- mockDocument.clearElements();
169
- });
170
-
171
- it('should find islands using CSS module in same directory', async () => {
172
- mockDocument.clearElements();
173
- mockDocument.clearListeners();
174
-
175
- const mockIsland = new MockHTMLElement();
176
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.tsx');
177
- mockIsland.setAttribute('data-framework', 'react');
178
- mockIsland.setAttribute('data-hydrated', 'true');
179
- mockDocument.addElement(mockIsland);
180
-
181
- const handler = new CSSHMRHandler();
182
- const update: Update = {
183
- type: 'css-update',
184
- path: '/src/islands/TestComponent.module.css',
185
- acceptedPath: '/src/islands/TestComponent.module.css',
186
- timestamp: Date.now(),
187
- };
188
-
189
- let rerenderEventFired = false;
190
- mockIsland.addEventListener('hmr-update-required', (e: Event) => {
191
- const customEvent = e as MockCustomEvent;
192
- rerenderEventFired = true;
193
- expect(customEvent.detail.reason).toBe('css-module-update');
194
- });
195
-
196
- await handler.handleCSSUpdate(update);
197
-
198
- expect(rerenderEventFired).toBe(true);
199
- handler.clearCache();
200
- mockDocument.clearElements();
201
- });
202
-
203
- it('should handle CSS module with no affected islands', async () => {
204
- mockDocument.clearElements();
205
-
206
- const handler = new CSSHMRHandler();
207
- const update: Update = {
208
- type: 'css-update',
209
- path: '/src/other/Unrelated.module.css',
210
- acceptedPath: '/src/other/Unrelated.module.css',
211
- timestamp: Date.now(),
212
- };
213
-
214
- // Should not throw error
215
- await handler.handleCSSUpdate(update);
216
- handler.clearCache();
217
- });
218
- });
219
-
220
- describe('CSSHMRHandler - Scoped CSS Updates', () => {
221
- it('should identify scoped CSS updates for Svelte', async () => {
222
- mockDocument.clearListeners();
223
- mockDocument.clearElements();
224
-
225
- // Add an island so the event fires
226
- const mockIsland = new MockHTMLElement();
227
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.svelte');
228
- mockDocument.addElement(mockIsland);
229
-
230
- const handler = new CSSHMRHandler();
231
- const update: Update = {
232
- type: 'css-update',
233
- path: '/src/islands/TestComponent.svelte',
234
- acceptedPath: '/src/islands/TestComponent.svelte',
235
- timestamp: Date.now(),
236
- };
237
-
238
- let eventFired = false;
239
- let eventDetail: any = null;
240
- mockDocument.addEventListener('css-hmr-update', (e: Event) => {
241
- const customEvent = e as MockCustomEvent;
242
- eventFired = true;
243
- eventDetail = customEvent.detail;
244
- });
245
-
246
- await handler.handleCSSUpdate(update);
247
-
248
- expect(eventFired).toBe(true);
249
- expect(eventDetail.type).toBe('scoped');
250
- handler.clearCache();
251
- mockDocument.clearElements();
252
- });
253
-
254
- it('should identify scoped CSS updates for Vue', async () => {
255
- mockDocument.clearListeners();
256
- mockDocument.clearElements();
257
-
258
- // Add an island so the event fires
259
- const mockIsland = new MockHTMLElement();
260
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.vue');
261
- mockDocument.addElement(mockIsland);
262
-
263
- const handler = new CSSHMRHandler();
264
- const update: Update = {
265
- type: 'css-update',
266
- path: '/src/islands/TestComponent.vue',
267
- acceptedPath: '/src/islands/TestComponent.vue',
268
- timestamp: Date.now(),
269
- };
270
-
271
- let eventFired = false;
272
- let eventDetail: any = null;
273
- mockDocument.addEventListener('css-hmr-update', (e: Event) => {
274
- const customEvent = e as MockCustomEvent;
275
- eventFired = true;
276
- eventDetail = customEvent.detail;
277
- });
278
-
279
- await handler.handleCSSUpdate(update);
280
-
281
- expect(eventFired).toBe(true);
282
- expect(eventDetail.type).toBe('scoped');
283
- handler.clearCache();
284
- mockDocument.clearElements();
285
- });
286
- });
287
-
288
- describe('CSSHMRHandler - CSS Module Registration', () => {
289
- it('should register CSS module usage explicitly', async () => {
290
- mockDocument.clearElements();
291
- mockDocument.clearListeners();
292
-
293
- const mockIsland = new MockHTMLElement();
294
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.tsx');
295
- mockDocument.addElement(mockIsland);
296
-
297
- const handler = new CSSHMRHandler();
298
- handler.registerCSSModuleUsage('/src/islands/Test.module.css', mockIsland as any);
299
-
300
- const update: Update = {
301
- type: 'css-update',
302
- path: '/src/islands/Test.module.css',
303
- acceptedPath: '/src/islands/Test.module.css',
304
- timestamp: Date.now(),
305
- };
306
-
307
- let eventFired = false;
308
- mockIsland.addEventListener('hmr-update-required', () => {
309
- eventFired = true;
310
- });
311
-
312
- await handler.handleCSSUpdate(update);
313
-
314
- expect(eventFired).toBe(true);
315
- handler.clearCache();
316
- mockDocument.clearElements();
317
- });
318
- });
319
-
320
- describe('CSSHMRHandler - Cache Management', () => {
321
- it('should clear cache', async () => {
322
- mockDocument.clearElements();
323
-
324
- const mockIsland = new MockHTMLElement();
325
- mockIsland.setAttribute('data-src', '/src/islands/TestComponent.tsx');
326
- mockDocument.addElement(mockIsland);
327
-
328
- const handler = new CSSHMRHandler();
329
- handler.registerCSSModuleUsage('/src/test.module.css', mockIsland as any);
330
- handler.clearCache();
331
-
332
- const update: Update = {
333
- type: 'css-update',
334
- path: '/src/test.module.css',
335
- acceptedPath: '/src/test.module.css',
336
- timestamp: Date.now(),
337
- };
338
-
339
- let eventFired = false;
340
- mockIsland.addEventListener('hmr-update-required', () => {
341
- eventFired = true;
342
- });
343
-
344
- await handler.handleCSSUpdate(update);
345
-
346
- // Should not find the island after cache clear
347
- expect(eventFired).toBe(false);
348
- handler.clearCache();
349
- mockDocument.clearElements();
350
- });
351
- });
352
-
353
- describe('CSSHMRHandler - Singleton Instance', () => {
354
- it('should return same instance from getCSSHMRHandler', () => {
355
- const instance1 = getCSSHMRHandler();
356
- const instance2 = getCSSHMRHandler();
357
-
358
- expect(instance1).toBe(instance2);
359
- });
360
- });