feat(core-shared/instrumentation): withCapture attaches runtime __captured marker
This commit is contained in:
@@ -3,6 +3,7 @@ import { withCapture } from "@/instrumentation/with-capture";
|
|||||||
import type { ILogger } from "@/instrumentation/logger.interface";
|
import type { ILogger } from "@/instrumentation/logger.interface";
|
||||||
import { isReported } from "@/instrumentation/reported-flag";
|
import { isReported } from "@/instrumentation/reported-flag";
|
||||||
import type { Captured } from "@/conformance/brands";
|
import type { Captured } from "@/conformance/brands";
|
||||||
|
import { isCaptured } from "@/conformance/brand-runtime";
|
||||||
|
|
||||||
function makeLogger(): ILogger & { captureException: ReturnType<typeof vi.fn> } {
|
function makeLogger(): ILogger & { captureException: ReturnType<typeof vi.fn> } {
|
||||||
return {
|
return {
|
||||||
@@ -70,3 +71,13 @@ describe("withCapture — brand", () => {
|
|||||||
expectTypeOf(wrapped).toMatchTypeOf<Captured<typeof fn>>();
|
expectTypeOf(wrapped).toMatchTypeOf<Captured<typeof fn>>();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("withCapture — runtime brand", () => {
|
||||||
|
it("attaches __captured as a non-enumerable property on the wrapped function", async () => {
|
||||||
|
const logger = makeLogger();
|
||||||
|
const fn = async (a: number) => a + 1;
|
||||||
|
const wrapped = withCapture(logger, { layer: "use-case" }, fn);
|
||||||
|
expect(isCaptured(wrapped)).toBe(true);
|
||||||
|
expect(Object.keys(wrapped)).not.toContain("__captured");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ILogger } from "./logger.interface";
|
import type { ILogger } from "./logger.interface";
|
||||||
import type { Captured } from "../conformance/brands";
|
import type { Captured } from "../conformance/brands";
|
||||||
|
import { attachBrand } from "../conformance/brand-runtime";
|
||||||
import { isReported, markReported } from "./reported-flag";
|
import { isReported, markReported } from "./reported-flag";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,5 +39,6 @@ export function withCapture<Args extends unknown[], R>(
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
attachBrand(wrapped, "__captured");
|
||||||
return wrapped as Captured<(...args: Args) => Promise<R>>;
|
return wrapped as Captured<(...args: Args) => Promise<R>>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user