@noego/testing 0.7.4 → 0.7.6
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/browser/index.js +3 -3
- package/dist/index.cjs +16 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -22
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/dist/index.js
CHANGED
|
@@ -330,7 +330,6 @@ function recordOutcome(call, outcome, threw) {
|
|
|
330
330
|
else call.result = outcome;
|
|
331
331
|
return outcome;
|
|
332
332
|
}
|
|
333
|
-
var pristineMethods = /* @__PURE__ */ new WeakMap();
|
|
334
333
|
function createMethodDecorator(registry) {
|
|
335
334
|
const wrappers = /* @__PURE__ */ new WeakMap();
|
|
336
335
|
return function decorate(instance, token2) {
|
|
@@ -351,18 +350,6 @@ function createMethodDecorator(registry) {
|
|
|
351
350
|
throw new MethodNotCallableError(tokenLabel(token2), method);
|
|
352
351
|
}
|
|
353
352
|
}
|
|
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
|
-
}
|
|
366
353
|
const methodCache = /* @__PURE__ */ new Map();
|
|
367
354
|
const proxy = new Proxy(instance, {
|
|
368
355
|
get(target, prop, receiver) {
|
|
@@ -370,7 +357,7 @@ function createMethodDecorator(registry) {
|
|
|
370
357
|
let wrapped = methodCache.get(prop);
|
|
371
358
|
if (!wrapped) {
|
|
372
359
|
const { entryKey, descriptor } = effective.get(prop);
|
|
373
|
-
wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop)
|
|
360
|
+
wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
|
|
374
361
|
methodCache.set(prop, wrapped);
|
|
375
362
|
}
|
|
376
363
|
return wrapped;
|
|
@@ -383,9 +370,10 @@ function createMethodDecorator(registry) {
|
|
|
383
370
|
return proxy;
|
|
384
371
|
};
|
|
385
372
|
}
|
|
386
|
-
function buildMethodWrapper(target, method, descriptor, state
|
|
373
|
+
function buildMethodWrapper(target, method, descriptor, state) {
|
|
387
374
|
const callOriginal = (self, args) => {
|
|
388
|
-
|
|
375
|
+
const fn = target[method];
|
|
376
|
+
return fn.apply(self === void 0 ? target : self, args);
|
|
389
377
|
};
|
|
390
378
|
if (typeof descriptor === "function") {
|
|
391
379
|
const replacement = descriptor((...args) => callOriginal(target, args));
|
|
@@ -1301,6 +1289,12 @@ function assertTestLanes(required, reports) {
|
|
|
1301
1289
|
}
|
|
1302
1290
|
|
|
1303
1291
|
// src/overlays.ts
|
|
1292
|
+
import { defineModule, flattenModule as flattenModule2 } from "@noego/ioc";
|
|
1293
|
+
function admittedClassBinding(token2) {
|
|
1294
|
+
return flattenModule2(defineModule("@noego/testing/admitted", (bind) => {
|
|
1295
|
+
bind(token2).toSelf();
|
|
1296
|
+
}))[0];
|
|
1297
|
+
}
|
|
1304
1298
|
var TestOverlayError = class extends Error {
|
|
1305
1299
|
constructor(message, entry) {
|
|
1306
1300
|
super("entry " + entry.provenance.join(".") + ": " + message);
|
|
@@ -1342,7 +1336,7 @@ function resolveTestOverlays(stub, catalogs) {
|
|
|
1342
1336
|
if (candidates.length === 0 && entry.kind !== "middleware" && entry.kind !== "load" && (typeof entry.target === "function" || entry.kind === "value")) {
|
|
1343
1337
|
const fallback = catalogs.filter((c) => entry.owner === void 0 || c.owner === entry.owner);
|
|
1344
1338
|
if (fallback.length === 1) {
|
|
1345
|
-
const synthetic = typeof entry.target === "function" ?
|
|
1339
|
+
const synthetic = typeof entry.target === "function" ? admittedClassBinding(entry.target) : { token: entry.target, kind: "value", lifetime: "singleton", implementation: entry.replacement, dependencies: [] };
|
|
1346
1340
|
candidates = [{ ...fallback[0], bindings: [...fallback[0].bindings, synthetic] }];
|
|
1347
1341
|
}
|
|
1348
1342
|
}
|
|
@@ -1364,7 +1358,7 @@ function resolveTestOverlays(stub, catalogs) {
|
|
|
1364
1358
|
}
|
|
1365
1359
|
|
|
1366
1360
|
// src/binding_overlays.ts
|
|
1367
|
-
import { defineModule } from "@noego/ioc";
|
|
1361
|
+
import { defineModule as defineModule2 } from "@noego/ioc";
|
|
1368
1362
|
function applyTestBindings(production, overlays, owner) {
|
|
1369
1363
|
let builder = production;
|
|
1370
1364
|
const entries = overlays.filter((e) => e.owner === owner);
|
|
@@ -1373,7 +1367,7 @@ function applyTestBindings(production, overlays, owner) {
|
|
|
1373
1367
|
const { entry, binding: binding2 } = overlay;
|
|
1374
1368
|
if (entry.kind === "middleware" || entry.kind === "load" || entry.kind === "method") continue;
|
|
1375
1369
|
if (!binding2) throw new TestOverlayError("missing production binding metadata", entry);
|
|
1376
|
-
builder = builder.use(
|
|
1370
|
+
builder = builder.use(defineModule2("@noego/testing/" + owner + "/" + entry.provenance.join("."), (bind) => {
|
|
1377
1371
|
if (entry.kind === "class") {
|
|
1378
1372
|
bind(entry.target).to(entry.replacement)[binding2.lifetime]();
|
|
1379
1373
|
} else if (entry.kind === "function" && binding2.kind === "factory") {
|
|
@@ -1438,15 +1432,15 @@ function createTestExecutables(overlays, owner) {
|
|
|
1438
1432
|
}
|
|
1439
1433
|
|
|
1440
1434
|
// src/binding_catalog.ts
|
|
1441
|
-
import { defineModule as
|
|
1435
|
+
import { defineModule as defineModule3, flattenModule as flattenModule3 } from "@noego/ioc";
|
|
1442
1436
|
function describeTestBindings(builder, discovered = []) {
|
|
1443
1437
|
const declarations = /* @__PURE__ */ new Map();
|
|
1444
|
-
const classBinding = (token2, implementation) =>
|
|
1438
|
+
const classBinding = (token2, implementation) => flattenModule3(defineModule3("@noego/testing/discovered", (bind) => {
|
|
1445
1439
|
bind(token2).to(implementation);
|
|
1446
1440
|
}))[0];
|
|
1447
1441
|
for (const write of builder.writes) {
|
|
1448
1442
|
if (write.op === "use") {
|
|
1449
|
-
for (const registration of
|
|
1443
|
+
for (const registration of flattenModule3(write.module)) declarations.set(registration.token, registration);
|
|
1450
1444
|
} else if (write.op === "classes") {
|
|
1451
1445
|
const registration = classBinding(write.key, write.implementation);
|
|
1452
1446
|
declarations.set(write.key, { ...registration, lifetime: declarations.get(write.key)?.lifetime ?? registration.lifetime });
|