@noego/testing 0.7.2 → 0.7.4

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.js CHANGED
@@ -330,6 +330,7 @@ function recordOutcome(call, outcome, threw) {
330
330
  else call.result = outcome;
331
331
  return outcome;
332
332
  }
333
+ var pristineMethods = /* @__PURE__ */ new WeakMap();
333
334
  function createMethodDecorator(registry) {
334
335
  const wrappers = /* @__PURE__ */ new WeakMap();
335
336
  return function decorate(instance, token2) {
@@ -350,6 +351,18 @@ function createMethodDecorator(registry) {
350
351
  throw new MethodNotCallableError(tokenLabel(token2), method);
351
352
  }
352
353
  }
354
+ if (Object.isExtensible(instance)) {
355
+ const pristine = pristineMethods.get(instance) ?? /* @__PURE__ */ new Map();
356
+ pristineMethods.set(instance, pristine);
357
+ for (const [method, { entryKey, descriptor }] of effective) {
358
+ const original = pristine.get(method) ?? instance[method];
359
+ pristine.set(method, original);
360
+ const wrapped = buildMethodWrapper(instance, method, descriptor, registry.state(entryKey, method), original);
361
+ Object.defineProperty(instance, method, { value: wrapped, configurable: true, writable: true, enumerable: false });
362
+ }
363
+ wrappers.set(instance, instance);
364
+ return instance;
365
+ }
353
366
  const methodCache = /* @__PURE__ */ new Map();
354
367
  const proxy = new Proxy(instance, {
355
368
  get(target, prop, receiver) {
@@ -357,7 +370,7 @@ function createMethodDecorator(registry) {
357
370
  let wrapped = methodCache.get(prop);
358
371
  if (!wrapped) {
359
372
  const { entryKey, descriptor } = effective.get(prop);
360
- wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
373
+ wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop), target[prop]);
361
374
  methodCache.set(prop, wrapped);
362
375
  }
363
376
  return wrapped;
@@ -370,10 +383,9 @@ function createMethodDecorator(registry) {
370
383
  return proxy;
371
384
  };
372
385
  }
373
- function buildMethodWrapper(target, method, descriptor, state) {
386
+ function buildMethodWrapper(target, method, descriptor, state, original) {
374
387
  const callOriginal = (self, args) => {
375
- const fn = target[method];
376
- return fn.apply(self === void 0 ? target : self, args);
388
+ return original.apply(self === void 0 ? target : self, args);
377
389
  };
378
390
  if (typeof descriptor === "function") {
379
391
  const replacement = descriptor((...args) => callOriginal(target, args));