@vitest/utils 1.6.0 → 2.0.0-beta.2

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.
@@ -46,7 +46,7 @@ function format(...args) {
46
46
  if (typeof args[0] !== "string") {
47
47
  const objects = [];
48
48
  for (let i2 = 0; i2 < args.length; i2++)
49
- objects.push(inspect(args[i2], { depth: 0, colors: false, compact: 3 }));
49
+ objects.push(inspect(args[i2], { depth: 0, colors: false }));
50
50
  return objects.join(" ");
51
51
  }
52
52
  const len = args.length;
@@ -65,7 +65,7 @@ function format(...args) {
65
65
  if (typeof value === "number" && value === 0 && 1 / value < 0)
66
66
  return "-0";
67
67
  if (typeof value === "object" && value !== null)
68
- return inspect(value, { depth: 0, colors: false, compact: 3 });
68
+ return inspect(value, { depth: 0, colors: false });
69
69
  return String(value);
70
70
  }
71
71
  case "%d": {
package/dist/diff.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DiffOptions } from './types-9l4niLY8.js';
2
- export { a as DiffOptionsColor } from './types-9l4niLY8.js';
1
+ import { D as DiffOptions } from './types-DyShQl4f.js';
2
+ export { a as DiffOptionsColor } from './types-DyShQl4f.js';
3
3
  import 'pretty-format';
4
4
 
5
5
  /**
package/dist/error.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { D as DiffOptions } from './types-9l4niLY8.js';
1
+ import { D as DiffOptions } from './types-DyShQl4f.js';
2
2
  import 'pretty-format';
3
3
 
4
4
  declare function serializeError(val: any, seen?: WeakMap<WeakKey, any>): any;
5
- declare function processError(err: any, diffOptions?: DiffOptions): any;
5
+ declare function processError(err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
6
6
  declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
7
7
  replacedActual: any;
8
8
  replacedExpected: any;
package/dist/error.js CHANGED
@@ -74,7 +74,7 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
74
74
  function normalizeErrorMessage(message) {
75
75
  return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
76
76
  }
77
- function processError(err, diffOptions) {
77
+ function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
78
78
  if (!err || typeof err !== "object")
79
79
  return { message: err };
80
80
  if (err.stack)
@@ -94,8 +94,13 @@ function processError(err, diffOptions) {
94
94
  try {
95
95
  if (typeof err.message === "string")
96
96
  err.message = normalizeErrorMessage(err.message);
97
- if (typeof err.cause === "object" && typeof err.cause.message === "string")
98
- err.cause.message = normalizeErrorMessage(err.cause.message);
97
+ } catch {
98
+ }
99
+ try {
100
+ if (!seen.has(err) && typeof err.cause === "object") {
101
+ seen.add(err);
102
+ err.cause = processError(err.cause, diffOptions, seen);
103
+ }
99
104
  } catch {
100
105
  }
101
106
  try {
package/dist/helpers.js CHANGED
@@ -61,8 +61,7 @@ function clone(val, seen, options = defaultCloneOptions) {
61
61
  if (Array.isArray(val)) {
62
62
  out = Array(k = val.length);
63
63
  seen.set(val, out);
64
- while (k--)
65
- out[k] = clone(val[k], seen, options);
64
+ while (k--) out[k] = clone(val[k], seen, options);
66
65
  return out;
67
66
  }
68
67
  if (Object.prototype.toString.call(val) === "[object Object]") {
package/dist/index.d.ts CHANGED
@@ -19,21 +19,21 @@ declare function setSafeTimers(): void;
19
19
 
20
20
  declare function shuffle<T>(array: T[], seed?: number): T[];
21
21
 
22
- interface LoupeOptions {
23
- showHidden?: boolean | undefined;
24
- depth?: number | null | undefined;
25
- colors?: boolean | undefined;
26
- customInspect?: boolean | undefined;
27
- showProxy?: boolean | undefined;
28
- maxArrayLength?: number | null | undefined;
29
- maxStringLength?: number | null | undefined;
30
- breakLength?: number | undefined;
31
- compact?: boolean | number | undefined;
32
- sorted?: boolean | ((a: string, b: string) => number) | undefined;
33
- getters?: 'get' | 'set' | boolean | undefined;
34
- numericSeparator?: boolean | undefined;
35
- truncate?: number;
22
+ type Inspect = (value: unknown, options: Options) => string;
23
+ interface Options {
24
+ showHidden: boolean;
25
+ depth: number;
26
+ colors: boolean;
27
+ customInspect: boolean;
28
+ showProxy: boolean;
29
+ maxArrayLength: number;
30
+ breakLength: number;
31
+ truncate: number;
32
+ seen: unknown[];
33
+ inspect: Inspect;
34
+ stylize: (value: string, styleType: string) => string;
36
35
  }
36
+ type LoupeOptions = Partial<Options>;
37
37
  declare function format(...args: unknown[]): string;
38
38
  declare function inspect(obj: unknown, options?: LoupeOptions): string;
39
39
  declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
@@ -14,6 +14,7 @@ interface SourceMapV3 {
14
14
  sources: (string | null)[];
15
15
  sourcesContent?: (string | null)[];
16
16
  version: 3;
17
+ ignoreList?: number[];
17
18
  }
18
19
  interface EncodedSourceMap extends SourceMapV3 {
19
20
  mappings: string;
@@ -42,7 +43,12 @@ type InvalidGeneratedMapping = {
42
43
  column: null;
43
44
  };
44
45
  type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
45
- type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
46
+ type XInput = {
47
+ x_google_ignoreList?: SourceMapV3['ignoreList'];
48
+ };
49
+ type EncodedSourceMapXInput = EncodedSourceMap & XInput;
50
+ type DecodedSourceMapXInput = DecodedSourceMap & XInput;
51
+ type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
46
52
  type Needle = {
47
53
  line: number;
48
54
  column: number;
@@ -62,25 +68,12 @@ declare abstract class SourceMap {
62
68
  sources: SourceMapV3['sources'];
63
69
  sourcesContent: SourceMapV3['sourcesContent'];
64
70
  resolvedSources: SourceMapV3['sources'];
71
+ ignoreList: SourceMapV3['ignoreList'];
65
72
  }
66
- type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
67
- type RoArray<T> = Ro<T>[];
68
- type RoObject<T> = {
69
- [K in keyof T]: T[K] | Ro<T[K]>;
70
- };
71
73
 
72
74
  declare const LEAST_UPPER_BOUND = -1;
73
75
  declare const GREATEST_LOWER_BOUND = 1;
74
- /**
75
- * A higher-level API to find the source/line/column associated with a generated line/column
76
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
77
- * `source-map` library.
78
- */
79
- declare let originalPositionFor: (map: TraceMap, needle: Needle) => OriginalMapping | InvalidOriginalMapping;
80
- /**
81
- * Finds the generated line/column position of the provided source/line/column source position.
82
- */
83
- declare let generatedPositionFor: (map: TraceMap, needle: SourceNeedle) => GeneratedMapping | InvalidGeneratedMapping;
76
+
84
77
  declare class TraceMap implements SourceMap {
85
78
  version: SourceMapV3['version'];
86
79
  file: SourceMapV3['file'];
@@ -88,6 +81,7 @@ declare class TraceMap implements SourceMap {
88
81
  sourceRoot: SourceMapV3['sourceRoot'];
89
82
  sources: SourceMapV3['sources'];
90
83
  sourcesContent: SourceMapV3['sourcesContent'];
84
+ ignoreList: SourceMapV3['ignoreList'];
91
85
  resolvedSources: string[];
92
86
  private _encoded;
93
87
  private _decoded;
@@ -96,6 +90,16 @@ declare class TraceMap implements SourceMap {
96
90
  private _bySourceMemos;
97
91
  constructor(map: SourceMapInput, mapUrl?: string | null);
98
92
  }
93
+ /**
94
+ * A higher-level API to find the source/line/column associated with a generated line/column
95
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
96
+ * `source-map` library.
97
+ */
98
+ declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
99
+ /**
100
+ * Finds the generated line/column position of the provided source/line/column source position.
101
+ */
102
+ declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
99
103
 
100
104
  interface StackTraceParserOptions {
101
105
  ignoreStackEntries?: (RegExp | string)[];
@@ -1,14 +1,15 @@
1
1
  import { notNullish, isPrimitive } from './helpers.js';
2
2
 
3
+ const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
3
4
  function normalizeWindowsPath(input = "") {
4
- if (!input || !input.includes("\\")) {
5
+ if (!input) {
5
6
  return input;
6
7
  }
7
- return input.replace(/\\/g, "/");
8
+ return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
8
9
  }
9
10
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
10
11
  function cwd() {
11
- if (typeof process !== "undefined") {
12
+ if (typeof process !== "undefined" && typeof process.cwd === "function") {
12
13
  return process.cwd().replace(/\\/g, "/");
13
14
  }
14
15
  return "/";
@@ -584,8 +585,9 @@ function buildBySources(decoded, memos) {
584
585
  // segment should go. Either way, we want to insert after that. And there may be multiple
585
586
  // generated segments associated with an original location, so there may need to move several
586
587
  // indexes before we find where we need to insert.
587
- const index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
588
- insert(originalLine, (memo.lastIndex = index + 1), [sourceColumn, i, seg[COLUMN]]);
588
+ let index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
589
+ memo.lastIndex = ++index;
590
+ insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
589
591
  }
590
592
  }
591
593
  return sources;
@@ -609,20 +611,6 @@ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
609
611
  const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
610
612
  const LEAST_UPPER_BOUND = -1;
611
613
  const GREATEST_LOWER_BOUND = 1;
612
- /**
613
- * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
614
- */
615
- let decodedMappings;
616
- /**
617
- * A higher-level API to find the source/line/column associated with a generated line/column
618
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
619
- * `source-map` library.
620
- */
621
- let originalPositionFor;
622
- /**
623
- * Finds the generated line/column position of the provided source/line/column source position.
624
- */
625
- let generatedPositionFor;
626
614
  class TraceMap {
627
615
  constructor(map, mapUrl) {
628
616
  const isString = typeof map === 'string';
@@ -636,6 +624,7 @@ class TraceMap {
636
624
  this.sourceRoot = sourceRoot;
637
625
  this.sources = sources;
638
626
  this.sourcesContent = sourcesContent;
627
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
639
628
  const from = resolve(sourceRoot || '', stripFilename(mapUrl));
640
629
  this.resolvedSources = sources.map((s) => resolve(s || '', from));
641
630
  const { mappings } = parsed;
@@ -652,60 +641,54 @@ class TraceMap {
652
641
  this._bySourceMemos = undefined;
653
642
  }
654
643
  }
655
- (() => {
656
- decodedMappings = (map) => {
657
- return (map._decoded || (map._decoded = decode(map._encoded)));
658
- };
659
- originalPositionFor = (map, { line, column, bias }) => {
660
- line--;
661
- if (line < 0)
662
- throw new Error(LINE_GTR_ZERO);
663
- if (column < 0)
664
- throw new Error(COL_GTR_EQ_ZERO);
665
- const decoded = decodedMappings(map);
666
- // It's common for parent source maps to have pointers to lines that have no
667
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
668
- if (line >= decoded.length)
669
- return OMapping(null, null, null, null);
670
- const segments = decoded[line];
671
- const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
672
- if (index === -1)
673
- return OMapping(null, null, null, null);
674
- const segment = segments[index];
675
- if (segment.length === 1)
676
- return OMapping(null, null, null, null);
677
- const { names, resolvedSources } = map;
678
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
679
- };
680
- generatedPositionFor = (map, { source, line, column, bias }) => {
681
- return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
682
- };
683
- function generatedPosition(map, source, line, column, bias, all) {
684
- line--;
685
- if (line < 0)
686
- throw new Error(LINE_GTR_ZERO);
687
- if (column < 0)
688
- throw new Error(COL_GTR_EQ_ZERO);
689
- const { sources, resolvedSources } = map;
690
- let sourceIndex = sources.indexOf(source);
691
- if (sourceIndex === -1)
692
- sourceIndex = resolvedSources.indexOf(source);
693
- if (sourceIndex === -1)
694
- return all ? [] : GMapping(null, null);
695
- const generated = (map._bySources || (map._bySources = buildBySources(decodedMappings(map), (map._bySourceMemos = sources.map(memoizedState)))));
696
- const segments = generated[sourceIndex][line];
697
- if (segments == null)
698
- return all ? [] : GMapping(null, null);
699
- const memo = map._bySourceMemos[sourceIndex];
700
- if (all)
701
- return sliceGeneratedPositions(segments, memo, line, column, bias);
702
- const index = traceSegmentInternal(segments, memo, line, column, bias);
703
- if (index === -1)
704
- return GMapping(null, null);
705
- const segment = segments[index];
706
- return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
707
- }
708
- })();
644
+ /**
645
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
646
+ * with public access modifiers.
647
+ */
648
+ function cast(map) {
649
+ return map;
650
+ }
651
+ /**
652
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
653
+ */
654
+ function decodedMappings(map) {
655
+ var _a;
656
+ return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
657
+ }
658
+ /**
659
+ * A higher-level API to find the source/line/column associated with a generated line/column
660
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
661
+ * `source-map` library.
662
+ */
663
+ function originalPositionFor(map, needle) {
664
+ let { line, column, bias } = needle;
665
+ line--;
666
+ if (line < 0)
667
+ throw new Error(LINE_GTR_ZERO);
668
+ if (column < 0)
669
+ throw new Error(COL_GTR_EQ_ZERO);
670
+ const decoded = decodedMappings(map);
671
+ // It's common for parent source maps to have pointers to lines that have no
672
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
673
+ if (line >= decoded.length)
674
+ return OMapping(null, null, null, null);
675
+ const segments = decoded[line];
676
+ const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
677
+ if (index === -1)
678
+ return OMapping(null, null, null, null);
679
+ const segment = segments[index];
680
+ if (segment.length === 1)
681
+ return OMapping(null, null, null, null);
682
+ const { names, resolvedSources } = map;
683
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
684
+ }
685
+ /**
686
+ * Finds the generated line/column position of the provided source/line/column source position.
687
+ */
688
+ function generatedPositionFor(map, needle) {
689
+ const { source, line, column, bias } = needle;
690
+ return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
691
+ }
709
692
  function OMapping(source, line, column, name) {
710
693
  return { source, line, column, name };
711
694
  }
@@ -750,6 +733,32 @@ function sliceGeneratedPositions(segments, memo, line, column, bias) {
750
733
  }
751
734
  return result;
752
735
  }
736
+ function generatedPosition(map, source, line, column, bias, all) {
737
+ var _a;
738
+ line--;
739
+ if (line < 0)
740
+ throw new Error(LINE_GTR_ZERO);
741
+ if (column < 0)
742
+ throw new Error(COL_GTR_EQ_ZERO);
743
+ const { sources, resolvedSources } = map;
744
+ let sourceIndex = sources.indexOf(source);
745
+ if (sourceIndex === -1)
746
+ sourceIndex = resolvedSources.indexOf(source);
747
+ if (sourceIndex === -1)
748
+ return all ? [] : GMapping(null, null);
749
+ const generated = ((_a = cast(map))._bySources || (_a._bySources = buildBySources(decodedMappings(map), (cast(map)._bySourceMemos = sources.map(memoizedState)))));
750
+ const segments = generated[sourceIndex][line];
751
+ if (segments == null)
752
+ return all ? [] : GMapping(null, null);
753
+ const memo = cast(map)._bySourceMemos[sourceIndex];
754
+ if (all)
755
+ return sliceGeneratedPositions(segments, memo, line, column, bias);
756
+ const index = traceSegmentInternal(segments, memo, line, column, bias);
757
+ if (index === -1)
758
+ return GMapping(null, null);
759
+ const segment = segments[index];
760
+ return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
761
+ }
753
762
 
754
763
  const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
755
764
  const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "1.6.0",
4
+ "version": "2.0.0-beta.2",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -59,11 +59,11 @@
59
59
  "dependencies": {
60
60
  "diff-sequences": "^29.6.3",
61
61
  "estree-walker": "^3.0.3",
62
- "loupe": "^2.3.7",
62
+ "loupe": "^3.1.0",
63
63
  "pretty-format": "^29.7.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@jridgewell/trace-mapping": "^0.3.22",
66
+ "@jridgewell/trace-mapping": "^0.3.25",
67
67
  "@types/estree": "^1.0.5",
68
68
  "tinyhighlight": "^0.3.2"
69
69
  },