Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export { JsonUtils } from "./jsonUtils/jsonUtils";
export { StringUtils } from "./stringUtils/stringUtils";
export { Utils, ExistingFileWriteActions } from "./utils/utils";
export type { AssertTypeMap, ActionAndParams } from "./utils/utils";

export { Mock } from "./mock/mock";
8 changes: 5 additions & 3 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ export class Logger {
const stackObj: unknown = {};
Error.captureStackTrace(stackObj as object, this.writeLine);
const stack = (stackObj as Error)?.stack ?? "[Unknown]";
const callingMethodDetails = this.callingMethodDetails(stack);
const callingMethodDetails = this.callingMethodDetails(stack, options?.stackOffset ?? 0);

const maxLines =
options?.maxLines ?? (this.options.writeLine.maxLines as number);
Expand Down Expand Up @@ -950,7 +950,7 @@ export class Logger {
}
}

private static callingMethodDetails(methodBase: string): string {
private static callingMethodDetails(methodBase: string, stackOffset = 0): string {
let methodName = "<Unknown>";
let typeName = "";
if (methodBase) {
Expand All @@ -962,7 +962,9 @@ export class Logger {
.findIndex((item) => !item.includes(LOGGER_STACK_FRAME_MARKER));
indexOfFirstNonLogLine =
indexOfFirstNonLogLine === -1 ? 1 : indexOfFirstNonLogLine + 1;
methodName = methodBaseLines[indexOfFirstNonLogLine]
const safeOffset = Math.max(0, stackOffset);
const targetIndex = Math.min(indexOfFirstNonLogLine + safeOffset, methodBaseLines.length - 1);
methodName = methodBaseLines[targetIndex]
.replace(/\s\s+/g, " ")
.trim();
if (methodName.startsWith("at ")) {
Expand Down
4 changes: 3 additions & 1 deletion src/logger/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export interface WriteLineOptions {
* // "MyTest.someStep (myTest.ts:45:3)"
* Logger.writeLine(Logger.Levels.TestInformation, message, { stackOffset: 1 });
*
* @remarks Not yet implemented — reserved for a future release.
* Values less than 1 are treated as 0 (no offset). Values that would exceed
* the available stack depth are clipped to the outermost frame.
*
*/
stackOffset?: number;
}
Expand Down
Loading
Loading