(
diffResult: ReadonlyArray<DiffResult<string>>,
options: BuildMessageOptions = {},
truncateDiff?: (
diffResult: ReadonlyArray<DiffResult<string>>,
stringDiff: boolean,
contextLength?: number | null,
) => ReadonlyArray<DiffResult<string>>,
)
| 107 | * ``` |
| 108 | */ |
| 109 | export function buildMessage( |
| 110 | diffResult: ReadonlyArray<DiffResult<string>>, |
| 111 | options: BuildMessageOptions = {}, |
| 112 | truncateDiff?: ( |
| 113 | diffResult: ReadonlyArray<DiffResult<string>>, |
| 114 | stringDiff: boolean, |
| 115 | contextLength?: number | null, |
| 116 | ) => ReadonlyArray<DiffResult<string>>, |
| 117 | ): string[] { |
| 118 | if (truncateDiff != null) { |
| 119 | diffResult = truncateDiff(diffResult, options.stringDiff ?? false); |
| 120 | } |
| 121 | |
| 122 | const { stringDiff = false } = options; |
| 123 | const messages = [ |
| 124 | "", |
| 125 | "", |
| 126 | ` ${gray(bold("[Diff]"))} ${red(bold("Actual"))} / ${ |
| 127 | green(bold("Expected")) |
| 128 | }`, |
| 129 | "", |
| 130 | "", |
| 131 | ]; |
| 132 | const diffMessages = diffResult.map((result) => { |
| 133 | const color = createColor(result.type); |
| 134 | |
| 135 | const line = result.type === "added" || result.type === "removed" |
| 136 | ? result.details?.map((detail) => |
| 137 | detail.type !== "common" |
| 138 | ? createColor(detail.type, true)(detail.value) |
| 139 | : detail.value |
| 140 | ).join("") ?? result.value |
| 141 | : result.value; |
| 142 | |
| 143 | return color(`${createSign(result.type)}${line}`); |
| 144 | }); |
| 145 | messages.push(...(stringDiff ? [diffMessages.join("")] : diffMessages), ""); |
| 146 | return messages; |
| 147 | } |
no test coverage detected