@vitest/utils 4.0.0-beta.10 → 4.0.0-beta.12

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.
@@ -1,158 +1,5 @@
1
- import { plugins, format as format$1 } from '@vitest/pretty-format';
2
- import * as loupe from 'loupe';
3
-
4
- const { AsymmetricMatcher, DOMCollection, DOMElement, Immutable, ReactElement, ReactTestComponent } = plugins;
5
- const PLUGINS = [
6
- ReactTestComponent,
7
- ReactElement,
8
- DOMElement,
9
- DOMCollection,
10
- Immutable,
11
- AsymmetricMatcher
12
- ];
13
- function stringify(object, maxDepth = 10, { maxLength,...options } = {}) {
14
- const MAX_LENGTH = maxLength ?? 1e4;
15
- let result;
16
- try {
17
- result = format$1(object, {
18
- maxDepth,
19
- escapeString: false,
20
- plugins: PLUGINS,
21
- ...options
22
- });
23
- } catch {
24
- result = format$1(object, {
25
- callToJSON: false,
26
- maxDepth,
27
- escapeString: false,
28
- plugins: PLUGINS,
29
- ...options
30
- });
31
- }
32
- // Prevents infinite loop https://github.com/vitest-dev/vitest/issues/7249
33
- return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(Math.min(maxDepth, Number.MAX_SAFE_INTEGER) / 2), {
34
- maxLength,
35
- ...options
36
- }) : result;
37
- }
38
- const formatRegExp = /%[sdjifoOc%]/g;
39
- function format(...args) {
40
- if (typeof args[0] !== "string") {
41
- const objects = [];
42
- for (let i = 0; i < args.length; i++) {
43
- objects.push(inspect(args[i], {
44
- depth: 0,
45
- colors: false
46
- }));
47
- }
48
- return objects.join(" ");
49
- }
50
- const len = args.length;
51
- let i = 1;
52
- const template = args[0];
53
- let str = String(template).replace(formatRegExp, (x) => {
54
- if (x === "%%") {
55
- return "%";
56
- }
57
- if (i >= len) {
58
- return x;
59
- }
60
- switch (x) {
61
- case "%s": {
62
- const value = args[i++];
63
- if (typeof value === "bigint") {
64
- return `${value.toString()}n`;
65
- }
66
- if (typeof value === "number" && value === 0 && 1 / value < 0) {
67
- return "-0";
68
- }
69
- if (typeof value === "object" && value !== null) {
70
- if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
71
- return value.toString();
72
- }
73
- return inspect(value, {
74
- depth: 0,
75
- colors: false
76
- });
77
- }
78
- return String(value);
79
- }
80
- case "%d": {
81
- const value = args[i++];
82
- if (typeof value === "bigint") {
83
- return `${value.toString()}n`;
84
- }
85
- return Number(value).toString();
86
- }
87
- case "%i": {
88
- const value = args[i++];
89
- if (typeof value === "bigint") {
90
- return `${value.toString()}n`;
91
- }
92
- return Number.parseInt(String(value)).toString();
93
- }
94
- case "%f": return Number.parseFloat(String(args[i++])).toString();
95
- case "%o": return inspect(args[i++], {
96
- showHidden: true,
97
- showProxy: true
98
- });
99
- case "%O": return inspect(args[i++]);
100
- case "%c": {
101
- i++;
102
- return "";
103
- }
104
- case "%j": try {
105
- return JSON.stringify(args[i++]);
106
- } catch (err) {
107
- const m = err.message;
108
- if (m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")) {
109
- return "[Circular]";
110
- }
111
- throw err;
112
- }
113
- default: return x;
114
- }
115
- });
116
- for (let x = args[i]; i < len; x = args[++i]) {
117
- if (x === null || typeof x !== "object") {
118
- str += ` ${x}`;
119
- } else {
120
- str += ` ${inspect(x)}`;
121
- }
122
- }
123
- return str;
124
- }
125
- function inspect(obj, options = {}) {
126
- if (options.truncate === 0) {
127
- options.truncate = Number.POSITIVE_INFINITY;
128
- }
129
- return loupe.inspect(obj, options);
130
- }
131
- function objDisplay(obj, options = {}) {
132
- if (typeof options.truncate === "undefined") {
133
- options.truncate = 40;
134
- }
135
- const str = inspect(obj, options);
136
- const type = Object.prototype.toString.call(obj);
137
- if (options.truncate && str.length >= options.truncate) {
138
- if (type === "[object Function]") {
139
- const fn = obj;
140
- return !fn.name ? "[Function]" : `[Function: ${fn.name}]`;
141
- } else if (type === "[object Array]") {
142
- return `[ Array(${obj.length}) ]`;
143
- } else if (type === "[object Object]") {
144
- const keys = Object.keys(obj);
145
- const kstr = keys.length > 2 ? `${keys.splice(0, 2).join(", ")}, ...` : keys.join(", ");
146
- return `{ Object (${kstr}) }`;
147
- } else {
148
- return str;
149
- }
150
- }
151
- return str;
152
- }
153
-
154
1
  function getDefaultExportFromCjs (x) {
155
2
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
156
3
  }
157
4
 
158
- export { format as f, getDefaultExportFromCjs as g, inspect as i, objDisplay as o, stringify as s };
5
+ export { getDefaultExportFromCjs as g };
@@ -0,0 +1,21 @@
1
+ declare const KNOWN_ASSET_TYPES: string[];
2
+ declare const KNOWN_ASSET_RE: RegExp;
3
+ declare const CSS_LANGS_RE: RegExp;
4
+ /**
5
+ * Prefix for resolved Ids that are not valid browser import specifiers
6
+ */
7
+ declare const VALID_ID_PREFIX = "/@id/";
8
+ /**
9
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
10
+ * module ID with `\0`, a convention from the rollup ecosystem.
11
+ * This prevents other plugins from trying to process the id (like node resolution),
12
+ * and core features like sourcemaps can use this info to differentiate between
13
+ * virtual modules and regular files.
14
+ * `\0` is not a permitted char in import URLs so we have to replace them during
15
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
16
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
17
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
18
+ */
19
+ declare const NULL_BYTE_PLACEHOLDER = "__x00__";
20
+
21
+ export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
@@ -0,0 +1,49 @@
1
+ // TODO: this is all copy pasted from Vite - can they expose a module that exports only constants?
2
+ const KNOWN_ASSET_TYPES = [
3
+ "apng",
4
+ "bmp",
5
+ "png",
6
+ "jpe?g",
7
+ "jfif",
8
+ "pjpeg",
9
+ "pjp",
10
+ "gif",
11
+ "svg",
12
+ "ico",
13
+ "webp",
14
+ "avif",
15
+ "mp4",
16
+ "webm",
17
+ "ogg",
18
+ "mp3",
19
+ "wav",
20
+ "flac",
21
+ "aac",
22
+ "woff2?",
23
+ "eot",
24
+ "ttf",
25
+ "otf",
26
+ "webmanifest",
27
+ "pdf",
28
+ "txt"
29
+ ];
30
+ const KNOWN_ASSET_RE = new RegExp(`\\.(${KNOWN_ASSET_TYPES.join("|")})$`);
31
+ const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
32
+ /**
33
+ * Prefix for resolved Ids that are not valid browser import specifiers
34
+ */
35
+ const VALID_ID_PREFIX = `/@id/`;
36
+ /**
37
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
38
+ * module ID with `\0`, a convention from the rollup ecosystem.
39
+ * This prevents other plugins from trying to process the id (like node resolution),
40
+ * and core features like sourcemaps can use this info to differentiate between
41
+ * virtual modules and regular files.
42
+ * `\0` is not a permitted char in import URLs so we have to replace them during
43
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
44
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
45
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
46
+ */
47
+ const NULL_BYTE_PLACEHOLDER = `__x00__`;
48
+
49
+ export { CSS_LANGS_RE, KNOWN_ASSET_RE, KNOWN_ASSET_TYPES, NULL_BYTE_PLACEHOLDER, VALID_ID_PREFIX };
package/dist/diff.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { plugins, format } from '@vitest/pretty-format';
2
2
  import c from 'tinyrainbow';
3
- import { g as getDefaultExportFromCjs, s as stringify } from './chunk-_commonjsHelpers.js';
4
- import { g as deepClone, k as getOwnProperties, l as getType$1 } from './chunk-helpers.js';
5
- import 'loupe';
3
+ import { stringify } from './display.js';
4
+ import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
5
+ import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
6
+ import './constants.js';
6
7
 
7
8
  /**
8
9
  * Diff Match and Patch
@@ -1301,7 +1302,7 @@ function requireBuild () {
1301
1302
  return build;
1302
1303
  }
1303
1304
 
1304
- var buildExports = requireBuild();
1305
+ var buildExports = /*@__PURE__*/ requireBuild();
1305
1306
  var diffSequences = /*@__PURE__*/getDefaultExportFromCjs(buildExports);
1306
1307
 
1307
1308
  function formatTrailingSpaces(line, trailingSpaceFormatter) {
@@ -0,0 +1,28 @@
1
+ import { PrettyFormatOptions } from '@vitest/pretty-format';
2
+
3
+ type Inspect = (value: unknown, options: Options) => string;
4
+ interface Options {
5
+ showHidden: boolean;
6
+ depth: number;
7
+ colors: boolean;
8
+ customInspect: boolean;
9
+ showProxy: boolean;
10
+ maxArrayLength: number;
11
+ breakLength: number;
12
+ truncate: number;
13
+ seen: unknown[];
14
+ inspect: Inspect;
15
+ stylize: (value: string, styleType: string) => string;
16
+ }
17
+ type LoupeOptions = Partial<Options>;
18
+ interface StringifyOptions extends PrettyFormatOptions {
19
+ maxLength?: number;
20
+ }
21
+ declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
22
+ declare const formatRegExp: RegExp;
23
+ declare function format(...args: unknown[]): string;
24
+ declare function inspect(obj: unknown, options?: LoupeOptions): string;
25
+ declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
26
+
27
+ export { format, formatRegExp, inspect, objDisplay, stringify };
28
+ export type { LoupeOptions, StringifyOptions };