@esmx/router-vue 3.0.0-rc.29 → 3.0.0-rc.31

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.
@@ -1,9 +1,11 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { beforeEach, describe, expect, it } from "vitest";
4
+ import { beforeEach, describe, expect, it, vi } from "vitest";
5
+ import { computed, nextTick, ref } from "vue";
5
6
  import { version } from "vue";
6
7
  import {
8
+ createDependentProxy,
7
9
  createSymbolProperty,
8
10
  isESModule,
9
11
  isVue3,
@@ -194,131 +196,155 @@ describe("util.ts - Utility Functions", () => {
194
196
  });
195
197
  });
196
198
  it("should return false for primitive values", () => {
197
- const primitives = ["string", 42, true, false, Symbol("test")];
199
+ const primitives = [42, "string", true, false, Symbol("test")];
198
200
  primitives.forEach((primitive) => {
199
201
  expect(isESModule(primitive)).toBe(false);
200
202
  });
201
203
  });
202
- });
203
- });
204
- describe("resolveComponent", () => {
205
- describe("should return null for falsy inputs", () => {
206
- const falsyValues = [null, void 0, false, 0, "", Number.NaN];
207
- falsyValues.forEach((value) => {
208
- it("should return null for ".concat(value), () => {
209
- expect(resolveComponent(value)).toBeNull();
204
+ it("should return false for functions and arrays", () => {
205
+ const nonObjects = [
206
+ () => {
207
+ },
208
+ () => {
209
+ },
210
+ [],
211
+ [1, 2, 3],
212
+ /* @__PURE__ */ new Date()
213
+ ];
214
+ nonObjects.forEach((nonObj) => {
215
+ expect(isESModule(nonObj)).toBe(false);
210
216
  });
211
217
  });
212
218
  });
213
- describe("should handle ES modules", () => {
214
- it("should return default export when available", () => {
215
- const defaultComponent = { name: "DefaultComponent" };
216
- const esModule = {
217
- __esModule: true,
218
- default: defaultComponent,
219
- namedExport: { name: "NamedComponent" }
220
- };
221
- const result = resolveComponent(esModule);
222
- expect(result).toBe(defaultComponent);
219
+ });
220
+ describe("resolveComponent", () => {
221
+ describe("should return default export or module itself", () => {
222
+ it("should return null for falsy values", () => {
223
+ expect(resolveComponent(null)).toBeNull();
224
+ expect(resolveComponent(void 0)).toBeNull();
225
+ expect(resolveComponent(false)).toBeNull();
226
+ expect(resolveComponent(0)).toBeNull();
227
+ expect(resolveComponent("")).toBeNull();
223
228
  });
224
- it("should return the module itself when no default export", () => {
225
- const esModule = {
229
+ it("should return default export if available", () => {
230
+ const defaultExport = { name: "DefaultComponent" };
231
+ const module = {
226
232
  __esModule: true,
227
- namedExport: { name: "NamedComponent" }
233
+ default: defaultExport,
234
+ other: "value"
228
235
  };
229
- const result = resolveComponent(esModule);
230
- expect(result).toBe(esModule);
236
+ expect(resolveComponent(module)).toBe(defaultExport);
231
237
  });
232
- it("should prefer default export over module when both exist", () => {
233
- const defaultComponent = { name: "DefaultComponent" };
234
- const esModule = {
238
+ it("should return the module itself if no default export", () => {
239
+ const module = {
235
240
  __esModule: true,
236
- default: defaultComponent,
237
- name: "ModuleComponent"
241
+ someExport: "value",
242
+ otherExport: 42
238
243
  };
239
- const result = resolveComponent(esModule);
240
- expect(result).toBe(defaultComponent);
241
- expect(result).not.toBe(esModule);
244
+ expect(resolveComponent(module)).toBe(module);
242
245
  });
243
246
  it("should handle modules with Symbol.toStringTag", () => {
244
- const defaultComponent = { name: "SymbolTagComponent" };
245
- const esModule = {
247
+ const defaultExport = { name: "SymbolDefaultComponent" };
248
+ const module = {
246
249
  [Symbol.toStringTag]: "Module",
247
- default: defaultComponent
250
+ default: defaultExport
248
251
  };
249
- const result = resolveComponent(esModule);
250
- expect(result).toBe(defaultComponent);
252
+ expect(resolveComponent(module)).toBe(defaultExport);
251
253
  });
252
- it("should handle falsy default export", () => {
253
- const falsyDefaults = [null, void 0, false, 0, ""];
254
- falsyDefaults.forEach((falsyDefault) => {
255
- const esModule = {
256
- __esModule: true,
257
- default: falsyDefault,
258
- fallback: { name: "FallbackComponent" }
259
- };
260
- const result = resolveComponent(esModule);
261
- expect(result).toBe(esModule);
262
- });
263
- });
264
- });
265
- describe("should handle non-ES modules", () => {
266
- it("should return component directly for non-ES modules", () => {
267
- const component = { name: "RegularComponent" };
268
- const result = resolveComponent(component);
269
- expect(result).toBe(component);
254
+ it("should return non-module objects as is", () => {
255
+ const nonModule = { prop: "value" };
256
+ expect(resolveComponent(nonModule)).toBe(nonModule);
270
257
  });
271
- it("should return function components directly", () => {
258
+ it("should handle various component types", () => {
272
259
  const functionComponent = () => ({ name: "FunctionComponent" });
273
- const result = resolveComponent(functionComponent);
274
- expect(result).toBe(functionComponent);
275
- });
276
- it("should return class components directly", () => {
260
+ expect(resolveComponent(functionComponent)).toBe(
261
+ functionComponent
262
+ );
277
263
  class ClassComponent {
278
264
  constructor() {
279
265
  __publicField(this, "name", "ClassComponent");
280
266
  }
281
267
  }
282
- const result = resolveComponent(ClassComponent);
283
- expect(result).toBe(ClassComponent);
268
+ const classInstance = new ClassComponent();
269
+ expect(resolveComponent(classInstance)).toBe(classInstance);
284
270
  });
285
271
  });
286
- describe("edge cases", () => {
287
- it("should handle circular references in modules", () => {
288
- const esModule = {
289
- __esModule: true
290
- };
291
- esModule.default = esModule;
292
- const result = resolveComponent(esModule);
293
- expect(result).toBe(esModule);
294
- });
295
- it("should handle deeply nested default exports", () => {
296
- const actualComponent = { name: "DeepComponent" };
297
- const esModule = {
298
- __esModule: true,
299
- default: {
300
- default: {
301
- default: actualComponent
302
- }
303
- }
304
- };
305
- const result = resolveComponent(esModule);
306
- expect(result).toEqual({
307
- default: {
308
- default: actualComponent
309
- }
310
- });
272
+ });
273
+ describe("createDependentProxy", () => {
274
+ it("should return original property values", () => {
275
+ const original = { foo: "bar", count: 42 };
276
+ const dep = ref(false);
277
+ const proxy = createDependentProxy(original, dep);
278
+ expect(proxy.foo).toBe("bar");
279
+ expect(proxy.count).toBe(42);
280
+ });
281
+ it("should handle method calls correctly", () => {
282
+ const original = {
283
+ items: [1, 2, 3],
284
+ getItems() {
285
+ return this.items;
286
+ }
287
+ };
288
+ const dep = ref(false);
289
+ const proxy = createDependentProxy(original, dep);
290
+ expect(proxy.getItems()).toEqual([1, 2, 3]);
291
+ expect(proxy.getItems()).toBe(original.items);
292
+ });
293
+ it("should handle nested property access", () => {
294
+ const original = {
295
+ nested: {
296
+ value: "nested-value"
297
+ }
298
+ };
299
+ const dep = ref(false);
300
+ const proxy = createDependentProxy(original, dep);
301
+ expect(proxy.nested.value).toBe("nested-value");
302
+ });
303
+ it("should allow property modification", () => {
304
+ const original = { value: "original" };
305
+ const dep = ref(false);
306
+ const proxy = createDependentProxy(original, dep);
307
+ proxy.value = "modified";
308
+ expect(proxy.value).toBe("modified");
309
+ expect(original.value).toBe("modified");
310
+ });
311
+ it("should trigger computed updates when dependency changes", async () => {
312
+ const original = { value: "test" };
313
+ const dep = ref(false);
314
+ const proxy = createDependentProxy(original, dep);
315
+ const computedValue = computed(() => {
316
+ return proxy.value + "-" + String(dep.value);
311
317
  });
312
- it("should handle modules with both __esModule and Symbol.toStringTag", () => {
313
- const defaultComponent = { name: "BothPropertiesComponent" };
314
- const esModule = {
315
- __esModule: true,
316
- [Symbol.toStringTag]: "Module",
317
- default: defaultComponent
318
- };
319
- const result = resolveComponent(esModule);
320
- expect(result).toBe(defaultComponent);
318
+ expect(computedValue.value).toBe("test-false");
319
+ dep.value = true;
320
+ await nextTick();
321
+ expect(computedValue.value).toBe("test-true");
322
+ proxy.value = "updated";
323
+ dep.value = false;
324
+ await nextTick();
325
+ expect(computedValue.value).toBe("updated-false");
326
+ });
327
+ it("should handle special properties", () => {
328
+ const symbol = Symbol("test");
329
+ const original = {
330
+ [symbol]: "symbol-value"
331
+ };
332
+ const dep = ref(false);
333
+ const proxy = createDependentProxy(original, dep);
334
+ expect(proxy[symbol]).toBe("symbol-value");
335
+ });
336
+ it("should read the dependency on property access", () => {
337
+ const original = { value: "test" };
338
+ const dep = ref(false);
339
+ const spy = vi.fn();
340
+ const depValue = dep.value;
341
+ vi.spyOn(dep, "value", "get").mockImplementation(() => {
342
+ spy();
343
+ return depValue;
321
344
  });
345
+ const proxy = createDependentProxy(original, dep);
346
+ proxy.value;
347
+ expect(spy).toHaveBeenCalled();
322
348
  });
323
349
  });
324
350
  });
package/package.json CHANGED
@@ -50,11 +50,11 @@
50
50
  "vue": "^3.5.0 || ^2.7.0"
51
51
  },
52
52
  "dependencies": {
53
- "@esmx/router": "3.0.0-rc.29"
53
+ "@esmx/router": "3.0.0-rc.31"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@biomejs/biome": "1.9.4",
57
- "@esmx/lint": "3.0.0-rc.29",
57
+ "@esmx/lint": "3.0.0-rc.31",
58
58
  "@types/node": "^24.0.0",
59
59
  "@vitest/coverage-v8": "3.2.4",
60
60
  "stylelint": "16.21.0",
@@ -64,7 +64,7 @@
64
64
  "vue": "3.5.13",
65
65
  "vue2": "npm:vue@2.7.16"
66
66
  },
67
- "version": "3.0.0-rc.29",
67
+ "version": "3.0.0-rc.31",
68
68
  "type": "module",
69
69
  "private": false,
70
70
  "exports": {
@@ -83,5 +83,5 @@
83
83
  "template",
84
84
  "public"
85
85
  ],
86
- "gitHead": "98aba9be77d48240c61d3bc7a507970533faa7da"
86
+ "gitHead": "d472904500f5d697cd61b99b012570f6b063c580"
87
87
  }
@@ -223,7 +223,7 @@ describe('plugin.ts - RouterPlugin', () => {
223
223
  await nextTick();
224
224
 
225
225
  // Verify the getter was called and returned correct value
226
- expect(routerResult).toBe(router);
226
+ expect(routerResult).toEqual(router);
227
227
  expect(routerResult).toBeInstanceOf(Router);
228
228
  });
229
229