@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.
- package/dist/plugin.test.mjs +1 -1
- package/dist/router-link.d.ts +1 -1
- package/dist/use.mjs +10 -8
- package/dist/use.test.mjs +113 -415
- package/dist/util.d.ts +2 -0
- package/dist/util.mjs +8 -0
- package/dist/util.test.mjs +123 -97
- package/package.json +4 -4
- package/src/plugin.test.ts +1 -1
- package/src/use.test.ts +135 -534
- package/src/use.ts +13 -13
- package/src/util.test.ts +128 -111
- package/src/util.ts +13 -0
package/dist/util.test.mjs
CHANGED
|
@@ -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",
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
|
225
|
-
const
|
|
229
|
+
it("should return default export if available", () => {
|
|
230
|
+
const defaultExport = { name: "DefaultComponent" };
|
|
231
|
+
const module = {
|
|
226
232
|
__esModule: true,
|
|
227
|
-
|
|
233
|
+
default: defaultExport,
|
|
234
|
+
other: "value"
|
|
228
235
|
};
|
|
229
|
-
|
|
230
|
-
expect(result).toBe(esModule);
|
|
236
|
+
expect(resolveComponent(module)).toBe(defaultExport);
|
|
231
237
|
});
|
|
232
|
-
it("should
|
|
233
|
-
const
|
|
234
|
-
const esModule = {
|
|
238
|
+
it("should return the module itself if no default export", () => {
|
|
239
|
+
const module = {
|
|
235
240
|
__esModule: true,
|
|
236
|
-
|
|
237
|
-
|
|
241
|
+
someExport: "value",
|
|
242
|
+
otherExport: 42
|
|
238
243
|
};
|
|
239
|
-
|
|
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
|
|
245
|
-
const
|
|
247
|
+
const defaultExport = { name: "SymbolDefaultComponent" };
|
|
248
|
+
const module = {
|
|
246
249
|
[Symbol.toStringTag]: "Module",
|
|
247
|
-
default:
|
|
250
|
+
default: defaultExport
|
|
248
251
|
};
|
|
249
|
-
|
|
250
|
-
expect(result).toBe(defaultComponent);
|
|
252
|
+
expect(resolveComponent(module)).toBe(defaultExport);
|
|
251
253
|
});
|
|
252
|
-
it("should
|
|
253
|
-
const
|
|
254
|
-
|
|
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
|
|
258
|
+
it("should handle various component types", () => {
|
|
272
259
|
const functionComponent = () => ({ name: "FunctionComponent" });
|
|
273
|
-
|
|
274
|
-
|
|
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
|
|
283
|
-
expect(
|
|
268
|
+
const classInstance = new ClassComponent();
|
|
269
|
+
expect(resolveComponent(classInstance)).toBe(classInstance);
|
|
284
270
|
});
|
|
285
271
|
});
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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": "
|
|
86
|
+
"gitHead": "d472904500f5d697cd61b99b012570f6b063c580"
|
|
87
87
|
}
|
package/src/plugin.test.ts
CHANGED
|
@@ -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).
|
|
226
|
+
expect(routerResult).toEqual(router);
|
|
227
227
|
expect(routerResult).toBeInstanceOf(Router);
|
|
228
228
|
});
|
|
229
229
|
|