@vitest/utils 2.0.0-beta.1 → 2.0.0-beta.11

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/diff.js CHANGED
@@ -21,14 +21,15 @@ function getType(value) {
21
21
  return "bigint";
22
22
  } else if (typeof value === "object") {
23
23
  if (value != null) {
24
- if (value.constructor === RegExp)
24
+ if (value.constructor === RegExp) {
25
25
  return "regexp";
26
- else if (value.constructor === Map)
26
+ } else if (value.constructor === Map) {
27
27
  return "map";
28
- else if (value.constructor === Set)
28
+ } else if (value.constructor === Set) {
29
29
  return "set";
30
- else if (value.constructor === Date)
30
+ } else if (value.constructor === Date) {
31
31
  return "date";
32
+ }
32
33
  }
33
34
  return "object";
34
35
  } else if (typeof value === "symbol") {
@@ -49,8 +50,9 @@ class Diff {
49
50
  }
50
51
  }
51
52
  const diff_commonPrefix = function(text1, text2) {
52
- if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0))
53
+ if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
53
54
  return 0;
55
+ }
54
56
  let pointermin = 0;
55
57
  let pointermax = Math.min(text1.length, text2.length);
56
58
  let pointermid = pointermax;
@@ -67,8 +69,9 @@ const diff_commonPrefix = function(text1, text2) {
67
69
  return pointermid;
68
70
  };
69
71
  const diff_commonSuffix = function(text1, text2) {
70
- if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1))
72
+ if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
71
73
  return 0;
74
+ }
72
75
  let pointermin = 0;
73
76
  let pointermax = Math.min(text1.length, text2.length);
74
77
  let pointermid = pointermax;
@@ -87,22 +90,26 @@ const diff_commonSuffix = function(text1, text2) {
87
90
  const diff_commonOverlap_ = function(text1, text2) {
88
91
  const text1_length = text1.length;
89
92
  const text2_length = text2.length;
90
- if (text1_length === 0 || text2_length === 0)
93
+ if (text1_length === 0 || text2_length === 0) {
91
94
  return 0;
92
- if (text1_length > text2_length)
95
+ }
96
+ if (text1_length > text2_length) {
93
97
  text1 = text1.substring(text1_length - text2_length);
94
- else if (text1_length < text2_length)
98
+ } else if (text1_length < text2_length) {
95
99
  text2 = text2.substring(0, text1_length);
100
+ }
96
101
  const text_length = Math.min(text1_length, text2_length);
97
- if (text1 === text2)
102
+ if (text1 === text2) {
98
103
  return text_length;
104
+ }
99
105
  let best = 0;
100
106
  let length = 1;
101
107
  while (true) {
102
108
  const pattern = text1.substring(text_length - length);
103
109
  const found = text2.indexOf(pattern);
104
- if (found === -1)
110
+ if (found === -1) {
105
111
  return best;
112
+ }
106
113
  length += found;
107
114
  if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
108
115
  best = length;
@@ -129,12 +136,17 @@ const diff_cleanupSemantic = function(diffs) {
129
136
  length_deletions2 = 0;
130
137
  lastEquality = diffs[pointer][1];
131
138
  } else {
132
- if (diffs[pointer][0] === DIFF_INSERT)
139
+ if (diffs[pointer][0] === DIFF_INSERT) {
133
140
  length_insertions2 += diffs[pointer][1].length;
134
- else
141
+ } else {
135
142
  length_deletions2 += diffs[pointer][1].length;
143
+ }
136
144
  if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
137
- diffs.splice(equalities[equalitiesLength - 1], 0, new Diff(DIFF_DELETE, lastEquality));
145
+ diffs.splice(
146
+ equalities[equalitiesLength - 1],
147
+ 0,
148
+ new Diff(DIFF_DELETE, lastEquality)
149
+ );
138
150
  diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
139
151
  equalitiesLength--;
140
152
  equalitiesLength--;
@@ -149,8 +161,9 @@ const diff_cleanupSemantic = function(diffs) {
149
161
  }
150
162
  pointer++;
151
163
  }
152
- if (changes)
164
+ if (changes) {
153
165
  diff_cleanupMerge(diffs);
166
+ }
154
167
  diff_cleanupSemanticLossless(diffs);
155
168
  pointer = 1;
156
169
  while (pointer < diffs.length) {
@@ -161,16 +174,30 @@ const diff_cleanupSemantic = function(diffs) {
161
174
  const overlap_length2 = diff_commonOverlap_(insertion, deletion);
162
175
  if (overlap_length1 >= overlap_length2) {
163
176
  if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
164
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1)));
165
- diffs[pointer - 1][1] = deletion.substring(0, deletion.length - overlap_length1);
177
+ diffs.splice(
178
+ pointer,
179
+ 0,
180
+ new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1))
181
+ );
182
+ diffs[pointer - 1][1] = deletion.substring(
183
+ 0,
184
+ deletion.length - overlap_length1
185
+ );
166
186
  diffs[pointer + 1][1] = insertion.substring(overlap_length1);
167
187
  pointer++;
168
188
  }
169
189
  } else {
170
190
  if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
171
- diffs.splice(pointer, 0, new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2)));
191
+ diffs.splice(
192
+ pointer,
193
+ 0,
194
+ new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2))
195
+ );
172
196
  diffs[pointer - 1][0] = DIFF_INSERT;
173
- diffs[pointer - 1][1] = insertion.substring(0, insertion.length - overlap_length2);
197
+ diffs[pointer - 1][1] = insertion.substring(
198
+ 0,
199
+ insertion.length - overlap_length2
200
+ );
174
201
  diffs[pointer + 1][0] = DIFF_DELETE;
175
202
  diffs[pointer + 1][1] = deletion.substring(overlap_length2);
176
203
  pointer++;
@@ -181,7 +208,7 @@ const diff_cleanupSemantic = function(diffs) {
181
208
  pointer++;
182
209
  }
183
210
  };
184
- const nonAlphaNumericRegex_ = /[^a-zA-Z0-9]/;
211
+ const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
185
212
  const whitespaceRegex_ = /\s/;
186
213
  const linebreakRegex_ = /[\r\n]/;
187
214
  const blanklineEndRegex_ = /\n\r?\n$/;
@@ -290,7 +317,11 @@ function diff_cleanupMerge(diffs) {
290
317
  if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
291
318
  diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
292
319
  } else {
293
- diffs.splice(0, 0, new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength)));
320
+ diffs.splice(
321
+ 0,
322
+ 0,
323
+ new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength))
324
+ );
294
325
  pointer++;
295
326
  }
296
327
  text_insert = text_insert.substring(commonlength);
@@ -299,8 +330,14 @@ function diff_cleanupMerge(diffs) {
299
330
  commonlength = diff_commonSuffix(text_insert, text_delete);
300
331
  if (commonlength !== 0) {
301
332
  diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
302
- text_insert = text_insert.substring(0, text_insert.length - commonlength);
303
- text_delete = text_delete.substring(0, text_delete.length - commonlength);
333
+ text_insert = text_insert.substring(
334
+ 0,
335
+ text_insert.length - commonlength
336
+ );
337
+ text_delete = text_delete.substring(
338
+ 0,
339
+ text_delete.length - commonlength
340
+ );
304
341
  }
305
342
  }
306
343
  pointer -= count_delete + count_insert;
@@ -327,14 +364,20 @@ function diff_cleanupMerge(diffs) {
327
364
  break;
328
365
  }
329
366
  }
330
- if (diffs[diffs.length - 1][1] === "")
367
+ if (diffs[diffs.length - 1][1] === "") {
331
368
  diffs.pop();
369
+ }
332
370
  let changes = false;
333
371
  pointer = 1;
334
372
  while (pointer < diffs.length - 1) {
335
373
  if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
336
- if (diffs[pointer][1].substring(diffs[pointer][1].length - diffs[pointer - 1][1].length) === diffs[pointer - 1][1]) {
337
- diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(0, diffs[pointer][1].length - diffs[pointer - 1][1].length);
374
+ if (diffs[pointer][1].substring(
375
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
376
+ ) === diffs[pointer - 1][1]) {
377
+ diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(
378
+ 0,
379
+ diffs[pointer][1].length - diffs[pointer - 1][1].length
380
+ );
338
381
  diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
339
382
  diffs.splice(pointer - 1, 1);
340
383
  changes = true;
@@ -347,8 +390,9 @@ function diff_cleanupMerge(diffs) {
347
390
  }
348
391
  pointer++;
349
392
  }
350
- if (changes)
393
+ if (changes) {
351
394
  diff_cleanupMerge(diffs);
395
+ }
352
396
  }
353
397
 
354
398
  const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
@@ -422,8 +466,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
422
466
  let i = 0;
423
467
  while (i !== iLength) {
424
468
  const iStart = i;
425
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
469
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
426
470
  i += 1;
471
+ }
427
472
  if (iStart !== i) {
428
473
  if (iStart === 0) {
429
474
  if (i > nContextLines) {
@@ -444,19 +489,22 @@ function joinAlignedDiffsNoExpand(diffs, options) {
444
489
  }
445
490
  }
446
491
  }
447
- while (i !== iLength && diffs[i][0] !== DIFF_EQUAL)
492
+ while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
448
493
  i += 1;
494
+ }
449
495
  }
450
496
  const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
451
- if (nExcessesBetweenChanges !== 0)
497
+ if (nExcessesBetweenChanges !== 0) {
452
498
  jLength += nExcessesBetweenChanges + 1;
453
- else if (hasExcessAtStartOrEnd)
499
+ } else if (hasExcessAtStartOrEnd) {
454
500
  jLength += 1;
501
+ }
455
502
  const jLast = jLength - 1;
456
503
  const lines = [];
457
504
  let jPatchMark = 0;
458
- if (hasPatch)
505
+ if (hasPatch) {
459
506
  lines.push("");
507
+ }
460
508
  let aStart = 0;
461
509
  let bStart = 0;
462
510
  let aEnd = 0;
@@ -480,8 +528,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
480
528
  i = 0;
481
529
  while (i !== iLength) {
482
530
  let iStart = i;
483
- while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
531
+ while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
484
532
  i += 1;
533
+ }
485
534
  if (iStart !== i) {
486
535
  if (iStart === 0) {
487
536
  if (i > nContextLines) {
@@ -491,18 +540,21 @@ function joinAlignedDiffsNoExpand(diffs, options) {
491
540
  aEnd = aStart;
492
541
  bEnd = bStart;
493
542
  }
494
- for (let iCommon = iStart; iCommon !== i; iCommon += 1)
543
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
495
544
  pushCommonLine(diffs[iCommon][1]);
545
+ }
496
546
  } else if (i === iLength) {
497
547
  const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
498
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
548
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
499
549
  pushCommonLine(diffs[iCommon][1]);
550
+ }
500
551
  } else {
501
552
  const nCommon = i - iStart;
502
553
  if (nCommon > nContextLines2) {
503
554
  const iEnd = iStart + nContextLines;
504
- for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
555
+ for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
505
556
  pushCommonLine(diffs[iCommon][1]);
557
+ }
506
558
  lines[jPatchMark] = createPatchMark(
507
559
  aStart,
508
560
  aEnd,
@@ -517,11 +569,13 @@ function joinAlignedDiffsNoExpand(diffs, options) {
517
569
  bStart = bEnd + nOmit;
518
570
  aEnd = aStart;
519
571
  bEnd = bStart;
520
- for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1)
572
+ for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
521
573
  pushCommonLine(diffs[iCommon][1]);
574
+ }
522
575
  } else {
523
- for (let iCommon = iStart; iCommon !== i; iCommon += 1)
576
+ for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
524
577
  pushCommonLine(diffs[iCommon][1]);
578
+ }
525
579
  }
526
580
  }
527
581
  }
@@ -534,8 +588,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
534
588
  i += 1;
535
589
  }
536
590
  }
537
- if (hasPatch)
591
+ if (hasPatch) {
538
592
  lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
593
+ }
539
594
  return lines.join("\n");
540
595
  }
541
596
  function joinAlignedDiffsExpand(diffs, options) {
@@ -625,8 +680,9 @@ function printAnnotation({
625
680
  includeChangeCounts,
626
681
  omitAnnotationLines
627
682
  }, changeCounts) {
628
- if (omitAnnotationLines)
683
+ if (omitAnnotationLines) {
629
684
  return "";
685
+ }
630
686
  let aRest = "";
631
687
  let bRest = "";
632
688
  if (includeChangeCounts) {
@@ -659,11 +715,7 @@ function diffLinesUnified(aLines, bLines, options) {
659
715
  isEmptyString(bLines) ? [] : bLines,
660
716
  normalizedOptions
661
717
  );
662
- return printDiffLines(
663
- diffs,
664
- truncated,
665
- normalizedOptions
666
- );
718
+ return printDiffLines(diffs, truncated, normalizedOptions);
667
719
  }
668
720
  function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
669
721
  if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
@@ -677,7 +729,11 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
677
729
  if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
678
730
  return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
679
731
  }
680
- const [diffs, truncated] = diffLinesRaw(aLinesCompare, bLinesCompare, options);
732
+ const [diffs, truncated] = diffLinesRaw(
733
+ aLinesCompare,
734
+ bLinesCompare,
735
+ options
736
+ );
681
737
  let aIndex = 0;
682
738
  let bIndex = 0;
683
739
  diffs.forEach((diff2) => {
@@ -700,7 +756,10 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
700
756
  }
701
757
  function diffLinesRaw(aLines, bLines, options) {
702
758
  const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
703
- const truncateThreshold = Math.max(Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0), 0);
759
+ const truncateThreshold = Math.max(
760
+ Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
761
+ 0
762
+ );
704
763
  const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
705
764
  const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
706
765
  const truncated = aLength !== aLines.length || bLength !== bLines.length;
@@ -709,19 +768,24 @@ function diffLinesRaw(aLines, bLines, options) {
709
768
  let aIndex = 0;
710
769
  let bIndex = 0;
711
770
  const foundSubsequence = (nCommon, aCommon, bCommon) => {
712
- for (; aIndex !== aCommon; aIndex += 1)
771
+ for (; aIndex !== aCommon; aIndex += 1) {
713
772
  diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
714
- for (; bIndex !== bCommon; bIndex += 1)
773
+ }
774
+ for (; bIndex !== bCommon; bIndex += 1) {
715
775
  diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
716
- for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1)
776
+ }
777
+ for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
717
778
  diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
779
+ }
718
780
  };
719
781
  const diffSequences = diff$1.default.default || diff$1.default;
720
782
  diffSequences(aLength, bLength, isCommon, foundSubsequence);
721
- for (; aIndex !== aLength; aIndex += 1)
783
+ for (; aIndex !== aLength; aIndex += 1) {
722
784
  diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
723
- for (; bIndex !== bLength; bIndex += 1)
785
+ }
786
+ for (; bIndex !== bLength; bIndex += 1) {
724
787
  diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
788
+ }
725
789
  return [diffs, truncated];
726
790
  }
727
791
 
@@ -730,7 +794,10 @@ function getNewLineSymbol(string) {
730
794
  }
731
795
  function diffStrings(a, b, options) {
732
796
  const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
733
- const truncateThreshold = Math.max(Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0), 0);
797
+ const truncateThreshold = Math.max(
798
+ Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
799
+ 0
800
+ );
734
801
  let aLength = a.length;
735
802
  let bLength = b.length;
736
803
  if (truncate) {
@@ -751,20 +818,24 @@ function diffStrings(a, b, options) {
751
818
  let bIndex = 0;
752
819
  const diffs = [];
753
820
  const foundSubsequence = (nCommon, aCommon, bCommon) => {
754
- if (aIndex !== aCommon)
821
+ if (aIndex !== aCommon) {
755
822
  diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
756
- if (bIndex !== bCommon)
823
+ }
824
+ if (bIndex !== bCommon) {
757
825
  diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
826
+ }
758
827
  aIndex = aCommon + nCommon;
759
828
  bIndex = bCommon + nCommon;
760
829
  diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
761
830
  };
762
831
  const diffSequences = diff$1.default.default || diff$1.default;
763
832
  diffSequences(aLength, bLength, isCommon, foundSubsequence);
764
- if (aIndex !== aLength)
833
+ if (aIndex !== aLength) {
765
834
  diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
766
- if (bIndex !== bLength)
835
+ }
836
+ if (bIndex !== bLength) {
767
837
  diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
838
+ }
768
839
  return [diffs, truncated];
769
840
  }
770
841
 
@@ -827,8 +898,9 @@ class ChangeBuffer {
827
898
  }
828
899
  // Output from buffer.
829
900
  moveLinesTo(lines) {
830
- if (!this.isLineEmpty())
901
+ if (!this.isLineEmpty()) {
831
902
  this.pushLine();
903
+ }
832
904
  lines.push(...this.lines);
833
905
  this.lines.length = 0;
834
906
  }
@@ -847,10 +919,12 @@ class CommonBuffer {
847
919
  }
848
920
  pushDiffChangeLines(diff) {
849
921
  const isDiffEmpty = diff[1].length === 0;
850
- if (!isDiffEmpty || this.deleteBuffer.isLineEmpty())
922
+ if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
851
923
  this.deleteBuffer.pushDiff(diff);
852
- if (!isDiffEmpty || this.insertBuffer.isLineEmpty())
924
+ }
925
+ if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
853
926
  this.insertBuffer.pushDiff(diff);
927
+ }
854
928
  }
855
929
  flushChangeLines() {
856
930
  this.deleteBuffer.moveLinesTo(this.lines);
@@ -939,8 +1013,9 @@ function diffStringsUnified(a, b, options) {
939
1013
  }
940
1014
  function diffStringsRaw(a, b, cleanup, options) {
941
1015
  const [diffs, truncated] = diffStrings(a, b, options);
942
- if (cleanup)
1016
+ if (cleanup) {
943
1017
  diff_cleanupSemantic(diffs);
1018
+ }
944
1019
  return [diffs, truncated];
945
1020
  }
946
1021
 
@@ -973,8 +1048,9 @@ const FALLBACK_FORMAT_OPTIONS = {
973
1048
  plugins: PLUGINS
974
1049
  };
975
1050
  function diff(a, b, options) {
976
- if (Object.is(a, b))
1051
+ if (Object.is(a, b)) {
977
1052
  return "";
1053
+ }
978
1054
  const aType = getType(a);
979
1055
  let expectedType = aType;
980
1056
  let omitDifference = false;
@@ -1001,8 +1077,9 @@ ${bDisplay}`;
1001
1077
 
1002
1078
  ${bDiff}`;
1003
1079
  }
1004
- if (omitDifference)
1080
+ if (omitDifference) {
1005
1081
  return null;
1082
+ }
1006
1083
  switch (aType) {
1007
1084
  case "string":
1008
1085
  return diffLinesUnified(a.split("\n"), b.split("\n"), options);
package/dist/error.js CHANGED
@@ -13,33 +13,45 @@ function isImmutable(v) {
13
13
  }
14
14
  const OBJECT_PROTO = Object.getPrototypeOf({});
15
15
  function getUnserializableMessage(err) {
16
- if (err instanceof Error)
16
+ if (err instanceof Error) {
17
17
  return `<unserializable>: ${err.message}`;
18
- if (typeof err === "string")
18
+ }
19
+ if (typeof err === "string") {
19
20
  return `<unserializable>: ${err}`;
21
+ }
20
22
  return "<unserializable>";
21
23
  }
22
24
  function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
23
- if (!val || typeof val === "string")
25
+ if (!val || typeof val === "string") {
24
26
  return val;
25
- if (typeof val === "function")
27
+ }
28
+ if (typeof val === "function") {
26
29
  return `Function<${val.name || "anonymous"}>`;
27
- if (typeof val === "symbol")
30
+ }
31
+ if (typeof val === "symbol") {
28
32
  return val.toString();
29
- if (typeof val !== "object")
33
+ }
34
+ if (typeof val !== "object") {
30
35
  return val;
31
- if (isImmutable(val))
36
+ }
37
+ if (isImmutable(val)) {
32
38
  return serializeError(val.toJSON(), seen);
33
- if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction")
39
+ }
40
+ if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction") {
34
41
  return "Promise";
35
- if (typeof Element !== "undefined" && val instanceof Element)
42
+ }
43
+ if (typeof Element !== "undefined" && val instanceof Element) {
36
44
  return val.tagName;
37
- if (typeof val.asymmetricMatch === "function")
45
+ }
46
+ if (typeof val.asymmetricMatch === "function") {
38
47
  return `${val.toString()} ${format(val.sample)}`;
39
- if (typeof val.toJSON === "function")
40
- return val.toJSON();
41
- if (seen.has(val))
48
+ }
49
+ if (typeof val.toJSON === "function") {
50
+ return serializeError(val.toJSON(), seen);
51
+ }
52
+ if (seen.has(val)) {
42
53
  return seen.get(val);
54
+ }
43
55
  if (Array.isArray(val)) {
44
56
  const clone = new Array(val.length);
45
57
  seen.set(val, clone);
@@ -57,8 +69,9 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
57
69
  let obj = val;
58
70
  while (obj && obj !== OBJECT_PROTO) {
59
71
  Object.getOwnPropertyNames(obj).forEach((key) => {
60
- if (key in clone)
72
+ if (key in clone) {
61
73
  return;
74
+ }
62
75
  try {
63
76
  clone[key] = serializeError(val[key], seen);
64
77
  } catch (err) {
@@ -75,25 +88,37 @@ function normalizeErrorMessage(message) {
75
88
  return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
76
89
  }
77
90
  function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
78
- if (!err || typeof err !== "object")
91
+ if (!err || typeof err !== "object") {
79
92
  return { message: err };
80
- if (err.stack)
93
+ }
94
+ if (err.stack) {
81
95
  err.stackStr = String(err.stack);
82
- if (err.name)
96
+ }
97
+ if (err.name) {
83
98
  err.nameStr = String(err.name);
99
+ }
84
100
  if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0) {
85
101
  const clonedActual = deepClone(err.actual, { forceWritable: true });
86
102
  const clonedExpected = deepClone(err.expected, { forceWritable: true });
87
- const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(clonedActual, clonedExpected);
88
- err.diff = diff(replacedExpected, replacedActual, { ...diffOptions, ...err.diffOptions });
103
+ const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(
104
+ clonedActual,
105
+ clonedExpected
106
+ );
107
+ err.diff = diff(replacedExpected, replacedActual, {
108
+ ...diffOptions,
109
+ ...err.diffOptions
110
+ });
89
111
  }
90
- if (typeof err.expected !== "string")
112
+ if (typeof err.expected !== "string") {
91
113
  err.expected = stringify(err.expected, 10);
92
- if (typeof err.actual !== "string")
114
+ }
115
+ if (typeof err.actual !== "string") {
93
116
  err.actual = stringify(err.actual, 10);
117
+ }
94
118
  try {
95
- if (typeof err.message === "string")
119
+ if (typeof err.message === "string") {
96
120
  err.message = normalizeErrorMessage(err.message);
121
+ }
97
122
  } catch {
98
123
  }
99
124
  try {
@@ -106,8 +131,12 @@ function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
106
131
  try {
107
132
  return serializeError(err);
108
133
  } catch (e) {
109
- return serializeError(new Error(`Failed to fully serialize error: ${e == null ? void 0 : e.message}
110
- Inner error message: ${err == null ? void 0 : err.message}`));
134
+ return serializeError(
135
+ new Error(
136
+ `Failed to fully serialize error: ${e == null ? void 0 : e.message}
137
+ Inner error message: ${err == null ? void 0 : err.message}`
138
+ )
139
+ );
111
140
  }
112
141
  }
113
142
  function isAsymmetricMatcher(data) {
@@ -120,21 +149,25 @@ function isReplaceable(obj1, obj2) {
120
149
  return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
121
150
  }
122
151
  function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
123
- if (!isReplaceable(actual, expected))
152
+ if (!isReplaceable(actual, expected)) {
124
153
  return { replacedActual: actual, replacedExpected: expected };
125
- if (actualReplaced.has(actual) || expectedReplaced.has(expected))
154
+ }
155
+ if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
126
156
  return { replacedActual: actual, replacedExpected: expected };
157
+ }
127
158
  actualReplaced.add(actual);
128
159
  expectedReplaced.add(expected);
129
160
  getOwnProperties(expected).forEach((key) => {
130
161
  const expectedValue = expected[key];
131
162
  const actualValue = actual[key];
132
163
  if (isAsymmetricMatcher(expectedValue)) {
133
- if (expectedValue.asymmetricMatch(actualValue))
164
+ if (expectedValue.asymmetricMatch(actualValue)) {
134
165
  actual[key] = expectedValue;
166
+ }
135
167
  } else if (isAsymmetricMatcher(actualValue)) {
136
- if (actualValue.asymmetricMatch(expectedValue))
168
+ if (actualValue.asymmetricMatch(expectedValue)) {
137
169
  expected[key] = actualValue;
170
+ }
138
171
  } else if (isReplaceable(actualValue, expectedValue)) {
139
172
  const replaced = replaceAsymmetricMatcher(
140
173
  actualValue,
package/dist/helpers.d.ts CHANGED
@@ -31,5 +31,6 @@ declare function createDefer<T>(): DeferPromise<T>;
31
31
  * ```
32
32
  */
33
33
  declare function getCallLastIndex(code: string): number | null;
34
+ declare function isNegativeNaN(val: number): boolean;
34
35
 
35
- export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
36
+ export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };