@noego/testing 0.7.1 → 0.7.3

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/index.cjs CHANGED
@@ -405,6 +405,15 @@ function createMethodDecorator(registry) {
405
405
  throw new MethodNotCallableError(tokenLabel(token2), method);
406
406
  }
407
407
  }
408
+ if (Object.isExtensible(instance)) {
409
+ for (const [method, { entryKey, descriptor }] of effective) {
410
+ const original = instance[method];
411
+ const wrapped = buildMethodWrapper(instance, method, descriptor, registry.state(entryKey, method), original);
412
+ Object.defineProperty(instance, method, { value: wrapped, configurable: true, writable: true, enumerable: false });
413
+ }
414
+ wrappers.set(instance, instance);
415
+ return instance;
416
+ }
408
417
  const methodCache = /* @__PURE__ */ new Map();
409
418
  const proxy = new Proxy(instance, {
410
419
  get(target, prop, receiver) {
@@ -412,7 +421,7 @@ function createMethodDecorator(registry) {
412
421
  let wrapped = methodCache.get(prop);
413
422
  if (!wrapped) {
414
423
  const { entryKey, descriptor } = effective.get(prop);
415
- wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
424
+ wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop), target[prop]);
416
425
  methodCache.set(prop, wrapped);
417
426
  }
418
427
  return wrapped;
@@ -425,10 +434,9 @@ function createMethodDecorator(registry) {
425
434
  return proxy;
426
435
  };
427
436
  }
428
- function buildMethodWrapper(target, method, descriptor, state) {
437
+ function buildMethodWrapper(target, method, descriptor, state, original) {
429
438
  const callOriginal = (self, args) => {
430
- const fn = target[method];
431
- return fn.apply(self === void 0 ? target : self, args);
439
+ return original.apply(self === void 0 ? target : self, args);
432
440
  };
433
441
  if (typeof descriptor === "function") {
434
442
  const replacement = descriptor((...args) => callOriginal(target, args));
@@ -1382,10 +1390,10 @@ function resolveTestOverlays(stub, catalogs) {
1382
1390
  const result = [];
1383
1391
  for (const entry of stubEntries(stub)) {
1384
1392
  let candidates = catalogs.filter((c) => owns(c, entry) && (entry.owner === void 0 || c.owner === entry.owner));
1385
- if (candidates.length === 0 && entry.kind !== "middleware" && entry.kind !== "load" && typeof entry.target === "function") {
1393
+ if (candidates.length === 0 && entry.kind !== "middleware" && entry.kind !== "load" && (typeof entry.target === "function" || entry.kind === "value")) {
1386
1394
  const fallback = catalogs.filter((c) => entry.owner === void 0 || c.owner === entry.owner);
1387
1395
  if (fallback.length === 1) {
1388
- const synthetic = { token: entry.target, kind: "class", lifetime: "singleton", implementation: entry.target, dependencies: [] };
1396
+ const synthetic = typeof entry.target === "function" ? { token: entry.target, kind: "class", lifetime: "singleton", implementation: entry.target, dependencies: [] } : { token: entry.target, kind: "value", lifetime: "singleton", implementation: entry.replacement, dependencies: [] };
1389
1397
  candidates = [{ ...fallback[0], bindings: [...fallback[0].bindings, synthetic] }];
1390
1398
  }
1391
1399
  }