MCPcopy Index your code
hub / github.com/nodejs/node / createErrDiff

Function createErrDiff

lib/internal/assert/assertion_error.js:185–236  ·  view source on GitHub ↗
(actual, expected, operator, customMessage, diffType = 'simple')

Source from the content-addressed store, hash-verified

183}
184
185function createErrDiff(actual, expected, operator, customMessage, diffType = 'simple') {
186 operator = checkOperator(actual, expected, operator);
187
188 let skipped = false;
189 let message = '';
190 const inspectedActual = inspectValue(actual);
191 const inspectedExpected = inspectValue(expected);
192 const inspectedSplitActual = StringPrototypeSplit(inspectedActual, '\n');
193 const inspectedSplitExpected = StringPrototypeSplit(inspectedExpected, '\n');
194 const showSimpleDiff = isSimpleDiff(actual, inspectedSplitActual, expected, inspectedSplitExpected);
195 let header = `${colors.green}+ actual${colors.white} ${colors.red}- expected${colors.white}`;
196
197 if (showSimpleDiff) {
198 const simpleDiff = getSimpleDiff(actual, inspectedSplitActual[0], expected, inspectedSplitExpected[0]);
199 message = simpleDiff.message;
200 if (typeof simpleDiff.header !== 'undefined') {
201 header = simpleDiff.header;
202 }
203 if (simpleDiff.skipped) {
204 skipped = true;
205 }
206 } else if (inspectedActual === inspectedExpected) {
207 // Handles the case where the objects are structurally the same but different references
208 operator = 'notIdentical';
209 if (inspectedSplitActual.length > 50 && diffType !== 'full') {
210 message = `${ArrayPrototypeJoin(ArrayPrototypeSlice(inspectedSplitActual, 0, 50), '\n')}\n...}`;
211 skipped = true;
212 } else {
213 message = ArrayPrototypeJoin(inspectedSplitActual, '\n');
214 }
215 header = '';
216 } else {
217 const checkCommaDisparity = actual != null && typeof actual === 'object';
218 const diff = myersDiff(inspectedSplitActual, inspectedSplitExpected, checkCommaDisparity);
219
220 const myersDiffMessage = printMyersDiff(diff, operator);
221 message = myersDiffMessage.message;
222
223 if (operator === 'partialDeepStrictEqual') {
224 header = `${colors.gray}${colors.hasColors ? '' : '+ '}actual${colors.white} ${colors.red}- expected${colors.white}`;
225 }
226
227 if (myersDiffMessage.skipped) {
228 skipped = true;
229 }
230 }
231
232 const headerMessage = `${getErrorMessage(operator, customMessage)}\n${header}`;
233 const skippedMessage = skipped ? '\n... Skipped lines' : '';
234
235 return `${headerMessage}${skippedMessage}\n${message}\n`;
236}
237
238function addEllipsis(string) {
239 const lines = StringPrototypeSplit(string, '\n', 11);

Callers 1

constructorMethod · 0.85

Calls 7

isSimpleDiffFunction · 0.85
getSimpleDiffFunction · 0.85
myersDiffFunction · 0.85
printMyersDiffFunction · 0.85
getErrorMessageFunction · 0.85
checkOperatorFunction · 0.70
inspectValueFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…