@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 +14 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -350,6 +350,15 @@ function createMethodDecorator(registry) {
|
|
|
350
350
|
throw new MethodNotCallableError(tokenLabel(token2), method);
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
+
if (Object.isExtensible(instance)) {
|
|
354
|
+
for (const [method, { entryKey, descriptor }] of effective) {
|
|
355
|
+
const original = instance[method];
|
|
356
|
+
const wrapped = buildMethodWrapper(instance, method, descriptor, registry.state(entryKey, method), original);
|
|
357
|
+
Object.defineProperty(instance, method, { value: wrapped, configurable: true, writable: true, enumerable: false });
|
|
358
|
+
}
|
|
359
|
+
wrappers.set(instance, instance);
|
|
360
|
+
return instance;
|
|
361
|
+
}
|
|
353
362
|
const methodCache = /* @__PURE__ */ new Map();
|
|
354
363
|
const proxy = new Proxy(instance, {
|
|
355
364
|
get(target, prop, receiver) {
|
|
@@ -357,7 +366,7 @@ function createMethodDecorator(registry) {
|
|
|
357
366
|
let wrapped = methodCache.get(prop);
|
|
358
367
|
if (!wrapped) {
|
|
359
368
|
const { entryKey, descriptor } = effective.get(prop);
|
|
360
|
-
wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
|
|
369
|
+
wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop), target[prop]);
|
|
361
370
|
methodCache.set(prop, wrapped);
|
|
362
371
|
}
|
|
363
372
|
return wrapped;
|
|
@@ -370,10 +379,9 @@ function createMethodDecorator(registry) {
|
|
|
370
379
|
return proxy;
|
|
371
380
|
};
|
|
372
381
|
}
|
|
373
|
-
function buildMethodWrapper(target, method, descriptor, state) {
|
|
382
|
+
function buildMethodWrapper(target, method, descriptor, state, original) {
|
|
374
383
|
const callOriginal = (self, args) => {
|
|
375
|
-
|
|
376
|
-
return fn.apply(self === void 0 ? target : self, args);
|
|
384
|
+
return original.apply(self === void 0 ? target : self, args);
|
|
377
385
|
};
|
|
378
386
|
if (typeof descriptor === "function") {
|
|
379
387
|
const replacement = descriptor((...args) => callOriginal(target, args));
|
|
@@ -1327,10 +1335,10 @@ function resolveTestOverlays(stub, catalogs) {
|
|
|
1327
1335
|
const result = [];
|
|
1328
1336
|
for (const entry of stubEntries(stub)) {
|
|
1329
1337
|
let candidates = catalogs.filter((c) => owns(c, entry) && (entry.owner === void 0 || c.owner === entry.owner));
|
|
1330
|
-
if (candidates.length === 0 && entry.kind !== "middleware" && entry.kind !== "load" && typeof entry.target === "function") {
|
|
1338
|
+
if (candidates.length === 0 && entry.kind !== "middleware" && entry.kind !== "load" && (typeof entry.target === "function" || entry.kind === "value")) {
|
|
1331
1339
|
const fallback = catalogs.filter((c) => entry.owner === void 0 || c.owner === entry.owner);
|
|
1332
1340
|
if (fallback.length === 1) {
|
|
1333
|
-
const synthetic = { token: entry.target, kind: "class", lifetime: "singleton", implementation: entry.target, dependencies: [] };
|
|
1341
|
+
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: [] };
|
|
1334
1342
|
candidates = [{ ...fallback[0], bindings: [...fallback[0].bindings, synthetic] }];
|
|
1335
1343
|
}
|
|
1336
1344
|
}
|