| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2331,6 +2331,13 @@ Color of truncate annotation, default is output with no color. | |||
| 2331 | 2331 | ||
| 2332 | 2332 | Print basic prototype `Object` and `Array` in diff output | |
| 2333 | 2333 | ||
| 2334 | + #### diff.maxDepth | ||
| 2335 | + | ||
| 2336 | + - **Type**: `number` | ||
| 2337 | + - **Default**: `20` (or `8` when comparing different types) | ||
| 2338 | + | ||
| 2339 | + Limit the depth to recurse when printing nested objects | ||
| 2340 | + | ||
| 2334 | 2341 | ### fakeTimers | |
| 2335 | 2342 | ||
| 2336 | 2343 | - **Type:** `FakeTimerInstallOpts` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,13 +53,14 @@ const PLUGINS = [ | |||
| 53 | 53 | prettyFormatPlugins.Error, | |
| 54 | 54 | ] | |
| 55 | 55 | const FORMAT_OPTIONS = { | |
| 56 | + maxDepth: 20, | ||
| 56 | 57 | plugins: PLUGINS, | |
| 57 | - } | ||
| 58 | + } satisfies PrettyFormatOptions | ||
| 58 | 59 | const FALLBACK_FORMAT_OPTIONS = { | |
| 59 | 60 | callToJSON: false, | |
| 60 | 61 | maxDepth: 8, | |
| 61 | 62 | plugins: PLUGINS, | |
| 62 | - } | ||
| 63 | + } satisfies PrettyFormatOptions | ||
| 63 | 64 | ||
| 64 | 65 | // Generate a string that will highlight the difference between two values | |
| 65 | 66 | // with green and red. (similar to how github does code diffing) | |
@@ -191,12 +192,13 @@ function getFormatOptions( | |||
| 191 | 192 | formatOptions: PrettyFormatOptions, | |
| 192 | 193 | options?: DiffOptions, | |
| 193 | 194 | ): PrettyFormatOptions { | |
| 194 | - const { compareKeys, printBasicPrototype } = normalizeDiffOptions(options) | ||
| 195 | + const { compareKeys, printBasicPrototype, maxDepth } = normalizeDiffOptions(options) | ||
| 195 | 196 | ||
| 196 | 197 | return { | |
| 197 | 198 | ...formatOptions, | |
| 198 | 199 | compareKeys, | |
| 199 | 200 | printBasicPrototype, | |
| 201 | + maxDepth: maxDepth ?? formatOptions.maxDepth, | ||
| 200 | 202 | } | |
| 201 | 203 | } | |
| 202 | 204 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ export interface DiffOptions { | |||
| 27 | 27 | omitAnnotationLines?: boolean | |
| 28 | 28 | patchColor?: DiffOptionsColor | |
| 29 | 29 | printBasicPrototype?: boolean | |
| 30 | + maxDepth?: number | ||
| 30 | 31 | compareKeys?: CompareKeys | |
| 31 | 32 | truncateThreshold?: number | |
| 32 | 33 | truncateAnnotation?: string | |
@@ -45,6 +46,7 @@ export interface SerializedDiffOptions { | |||
| 45 | 46 | includeChangeCounts?: boolean | |
| 46 | 47 | omitAnnotationLines?: boolean | |
| 47 | 48 | printBasicPrototype?: boolean | |
| 49 | + maxDepth?: number | ||
| 48 | 50 | truncateThreshold?: number | |
| 49 | 51 | truncateAnnotation?: string | |
| 50 | 52 | } | |
@@ -69,6 +71,7 @@ export interface DiffOptionsNormalized { | |||
| 69 | 71 | omitAnnotationLines: boolean | |
| 70 | 72 | patchColor: DiffOptionsColor | |
| 71 | 73 | printBasicPrototype: boolean | |
| 74 | + maxDepth?: number | ||
| 72 | 75 | truncateThreshold: number | |
| 73 | 76 | truncateAnnotation: string | |
| 74 | 77 | truncateAnnotationColor: DiffOptionsColor | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -648,6 +648,10 @@ export const cliOptionsConfig: VitestCLIOptions = { | |||
| 648 | 648 | printBasicPrototype: { | |
| 649 | 649 | description: 'Print basic prototype Object and Array (default: `true`)', | |
| 650 | 650 | }, | |
| 651 | + maxDepth: { | ||
| 652 | + description: 'Limit the depth to recurse when printing nested objects (default: `20`)', | ||
| 653 | + argument: '<maxDepth>', | ||
| 654 | + }, | ||
| 651 | 655 | truncateThreshold: { | |
| 652 | 656 | description: 'Number of lines to show before and after each change (default: `0`)', | |
| 653 | 657 | argument: '<threshold>', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,6 +324,25 @@ test('truncate large diff', () => { | |||
| 324 | 324 | expect(diff.trim()).toMatch(/\.\.\.$/) | |
| 325 | 325 | }) | |
| 326 | 326 | ||
| 327 | + test('diff default maxDepth', () => { | ||
| 328 | + function generateCycle(n: number) { | ||
| 329 | + const nodes = Array.from({ length: n }, (_, i) => ({ i, next: null as any })) | ||
| 330 | + nodes.forEach((node, i) => { | ||
| 331 | + node.next = nodes[(i + 1) % n] | ||
| 332 | + }) | ||
| 333 | + return nodes | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + // diff only appears in a deeper depth than maxDepth | ||
| 337 | + const xs = generateCycle(20) | ||
| 338 | + const ys = generateCycle(20) | ||
| 339 | + ys[10].i = -1 | ||
| 340 | + const diff = getErrorDiff(xs[0], ys[0], { maxDepth: 5 }) | ||
| 341 | + expect(stripVTControlCharacters(diff)).toMatchInlineSnapshot( | ||
| 342 | + `"Compared values have no visual difference."`, | ||
| 343 | + ) | ||
| 344 | + }) | ||
| 345 | + | ||
| 327 | 346 | function getErrorDiff(actual: unknown, expected: unknown, options?: DiffOptions): string { | |
| 328 | 347 | try { | |
| 329 | 348 | expect(actual).toEqual(expected) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments