@svadmin/core 0.23.3 → 0.23.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/core",
3
- "version": "0.23.3",
3
+ "version": "0.23.5",
4
4
  "author": "zuohuadong",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,15 +1,10 @@
1
1
  // Unit tests for RouterProvider implementations
2
- // Router provider tests need a DOM environment.
3
- // Skip if window is not available (CI without happy-dom).
4
- import { describe, test, expect } from 'bun:test';
2
+ // Router provider tests need a DOM environment or a mock.
3
+ import { describe, test, expect, beforeEach } from 'bun:test';
5
4
  import { createHashRouterProvider, createHistoryRouterProvider } from './router-provider';
6
- import { GlobalRegistrator } from '@happy-dom/global-registrator';
7
-
8
- GlobalRegistrator.register();
9
-
10
- const hasWindow = typeof globalThis.window !== 'undefined';
11
5
 
12
6
  describe('createHashRouterProvider (unit — no DOM)', () => {
7
+
13
8
  test('returns provider with go, back, parse methods', () => {
14
9
  const provider = createHashRouterProvider();
15
10
  expect(typeof provider.go).toBe('function');
@@ -32,8 +27,20 @@ describe('createHistoryRouterProvider (unit — no DOM)', () => {
32
27
  });
33
28
  });
34
29
 
35
- // DOM-dependent tests — only run if window is available
36
- describe.skipIf(!hasWindow)('createHashRouterProvider (DOM)', () => {
30
+ // DOM-dependent tests — mocked window if not exists
31
+ describe('createHashRouterProvider (with mock DOM)', () => {
32
+ beforeEach(() => {
33
+ if (typeof globalThis.window === 'undefined') {
34
+ let _hash = '';
35
+ (globalThis as any).window = {
36
+ location: {
37
+ get hash() { return _hash ? (_hash.startsWith('#') ? _hash : '#' + _hash) : ''; },
38
+ set hash(val) { _hash = val; }
39
+ }
40
+ };
41
+ }
42
+ });
43
+
37
44
  test('parse returns empty segments for root', () => {
38
45
  window.location.hash = '';
39
46
  const provider = createHashRouterProvider();
@@ -72,3 +79,4 @@ describe.skipIf(!hasWindow)('createHashRouterProvider (DOM)', () => {
72
79
  expect(window.location.hash).toBe('#/users');
73
80
  });
74
81
  });
82
+
package/src/router.ts CHANGED
@@ -1,8 +1,11 @@
1
1
  // Router — path matching + navigation (supports hash & history via RouterProvider)
2
2
 
3
3
  import type { RouterProvider } from './router-provider';
4
- import { syncGlobalPath } from './useParsed.svelte';
5
4
 
5
+ let _syncGlobalPath: () => void = () => {};
6
+ export function registerRouterSync(fn: () => void) {
7
+ _syncGlobalPath = fn;
8
+ }
6
9
  interface RouteMatch {
7
10
  route: string;
8
11
  params: Record<string, string>;
@@ -75,7 +78,7 @@ export async function navigate(path: string, options?: { replaceState?: boolean
75
78
  } else if (typeof window !== 'undefined') {
76
79
  window.location.hash = '#' + path.replace(/^#/, '');
77
80
  }
78
- syncGlobalPath();
81
+ _syncGlobalPath();
79
82
  for (const guard of _afterGuards) {
80
83
  guard(path, from);
81
84
  }
@@ -1,6 +1,6 @@
1
1
  // useParsed — parse current URL hash into structured route info
2
2
 
3
- import { currentPath } from './router';
3
+ import { currentPath, registerRouterSync } from './router';
4
4
  import { getResources } from './context.svelte';
5
5
 
6
6
  interface ParsedRoute {
@@ -19,6 +19,8 @@ export function resetGlobalPath(): void {
19
19
  export function syncGlobalPath(): void {
20
20
  if (typeof window !== 'undefined') globalPath = currentPath();
21
21
  }
22
+ registerRouterSync(syncGlobalPath);
23
+
22
24
  if (typeof window !== 'undefined') {
23
25
  globalPath = currentPath();
24
26
  if (!(window as any).__svadminParsedInit) {