@noego/testing 0.7.0 → 0.7.1

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
@@ -1326,15 +1326,22 @@ function resolveTestOverlays(stub, catalogs) {
1326
1326
  if (new Set(names).size !== names.length) throw new TypeError("duplicate test owner catalog");
1327
1327
  const result = [];
1328
1328
  for (const entry of stubEntries(stub)) {
1329
- const candidates = catalogs.filter((c) => owns(c, entry) && (entry.owner === void 0 || c.owner === entry.owner));
1329
+ 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") {
1331
+ const fallback = catalogs.filter((c) => entry.owner === void 0 || c.owner === entry.owner);
1332
+ if (fallback.length === 1) {
1333
+ const synthetic = { token: entry.target, kind: "class", lifetime: "singleton", implementation: entry.target, dependencies: [] };
1334
+ candidates = [{ ...fallback[0], bindings: [...fallback[0].bindings, synthetic] }];
1335
+ }
1336
+ }
1330
1337
  if (candidates.length !== 1) {
1331
1338
  const identity2 = entry.kind === "load" ? entry.target.path + "#" + entry.target.export : label2(entry.target);
1332
1339
  throw new TestOverlayError((candidates.length ? "Ambiguous" : "Unknown") + " " + entry.kind + ' "' + identity2 + '" in selected owners [' + names.join(", ") + "]" + (entry.owner ? "; requested owner " + entry.owner : "; specify { owner } when ambiguous"), entry);
1333
1340
  }
1334
1341
  const catalog = candidates[0];
1335
1342
  const declared = entry.kind === "middleware" || entry.kind === "load" ? void 0 : binding(catalog, entry.target);
1336
- if (entry.kind === "function" && declared?.kind !== "factory" && !(declared?.kind === "value" && typeof declared.implementation === "function")) {
1337
- throw new TestOverlayError(".function requires a declared factory/provider or callable value binding", entry);
1343
+ if (entry.kind === "function" && declared?.kind !== "factory" && declared?.kind !== "class" && !(declared?.kind === "value" && typeof declared.implementation === "function")) {
1344
+ throw new TestOverlayError(".function requires a declared factory/provider, class, or callable value binding", entry);
1338
1345
  }
1339
1346
  const resolved = Object.freeze({ owner: catalog.owner, entry, binding: declared });
1340
1347
  const prior = result.findIndex((e) => sameSlot(e, resolved));
@@ -1359,6 +1366,9 @@ function applyTestBindings(production, overlays, owner) {
1359
1366
  bind(entry.target).to(entry.replacement)[binding2.lifetime]();
1360
1367
  } else if (entry.kind === "function" && binding2.kind === "factory") {
1361
1368
  bind(entry.target).toFactory(entry.replacement, [...binding2.dependencies])[binding2.lifetime]();
1369
+ } else if (entry.kind === "function" && binding2.kind === "class") {
1370
+ bind(entry.target).toFactory(() => entry.replacement())[binding2.lifetime]();
1371
+ borrowed.push(entry.target);
1362
1372
  } else {
1363
1373
  bind(entry.target).toFactory(() => entry.replacement)[binding2.lifetime]();
1364
1374
  borrowed.push(entry.target);