From 4239b102683004b2ba5f0535ca33e9b8a3c1d929 Mon Sep 17 00:00:00 2001 From: Ivan Todoroski Date: Fri, 10 May 2019 21:12:25 -0700 Subject: [PATCH 1/4] Make the object printing depth configurable Respect NodeJS's util.inspect.defaultOptions.depth setting when printing objects. --- lib/concordance-options.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/concordance-options.js b/lib/concordance-options.js index b3390a4b3..8d156220d 100644 --- a/lib/concordance-options.js +++ b/lib/concordance-options.js @@ -1,4 +1,5 @@ 'use strict'; +const util = require('util'); const ansiStyles = require('ansi-styles'); const stripAnsi = require('strip-ansi'); const cloneDeepWith = require('lodash.clonedeepwith'); @@ -124,6 +125,6 @@ const plainTheme = cloneDeepWith(colorTheme, value => { }); const theme = chalk.enabled ? colorTheme : plainTheme; -exports.default = {maxDepth: 3, plugins, theme}; +exports.default = {maxDepth: util.inspect.defaultOptions.depth, plugins, theme}; exports.diff = {maxDepth: 1, plugins, theme}; exports.snapshotManager = {plugins, theme: plainTheme}; From f458070c8c894251c64b0c0588b3221186424e1e Mon Sep 17 00:00:00 2001 From: Ivan Todoroski Date: Mon, 13 May 2019 09:58:29 -0700 Subject: [PATCH 2/4] Make the depth dynamically reconfigurable after Ava is loaded, and also clamp it to a minimum of 3 --- lib/concordance-options.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/concordance-options.js b/lib/concordance-options.js index 8d156220d..0e6193211 100644 --- a/lib/concordance-options.js +++ b/lib/concordance-options.js @@ -125,6 +125,15 @@ const plainTheme = cloneDeepWith(colorTheme, value => { }); const theme = chalk.enabled ? colorTheme : plainTheme; -exports.default = {maxDepth: util.inspect.defaultOptions.depth, plugins, theme}; + +exports.default = { + // Use Node's object inspection depth, clamped to a minimum of 3 + get maxDepth() { + return Math.max(3, util.inspect.defaultOptions.depth); + }, + plugins, + theme +}; + exports.diff = {maxDepth: 1, plugins, theme}; exports.snapshotManager = {plugins, theme: plainTheme}; From 95c2ba03e6fce1fe3b66748890faa1f0150fa6ee Mon Sep 17 00:00:00 2001 From: Ivan Todoroski Date: Mon, 20 May 2019 10:46:37 -0700 Subject: [PATCH 3/4] Document how to change the object printing depth --- docs/06-configuration.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/06-configuration.md b/docs/06-configuration.md index 7724271b3..2242e9638 100644 --- a/docs/06-configuration.md +++ b/docs/06-configuration.md @@ -107,3 +107,20 @@ export default ({projectDir}) => { ``` Note that the final configuration must not be a promise. + +## Object printing depth + +By default, Ava prints nested objects to a depth of 3. However, when debugging tests it's sometimes useful to print more detail in highly nested objects. This can be done by setting [`util.inspect.defaultOptions.depth`](https://nodejs.org/api/util.html#util_util_inspect_defaultoptions) to the desired depth, before the test is executed: + +```js +import test from 'ava'; +import util from 'util'; // import the "util" module from Node.js + +util.inspect.defaultOptions.depth = 5; // set the depth + +... + +test("My test", ...); +``` + +The minimum object printing depth is 3. If it's set lower than 3, Ava will still print 3 levels of nested objects. From 4a1b81b5b69cb78593291cb70684c8bcccb2d79a Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sat, 25 May 2019 16:43:12 +0200 Subject: [PATCH 4/4] Tweak docs --- docs/06-configuration.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/06-configuration.md b/docs/06-configuration.md index 2242e9638..689233cf8 100644 --- a/docs/06-configuration.md +++ b/docs/06-configuration.md @@ -110,17 +110,18 @@ Note that the final configuration must not be a promise. ## Object printing depth -By default, Ava prints nested objects to a depth of 3. However, when debugging tests it's sometimes useful to print more detail in highly nested objects. This can be done by setting [`util.inspect.defaultOptions.depth`](https://nodejs.org/api/util.html#util_util_inspect_defaultoptions) to the desired depth, before the test is executed: +By default, AVA prints nested objects to a depth of `3`. However, when debugging tests with deeply nested objects, it can be useful to print with more detail. This can be done by setting [`util.inspect.defaultOptions.depth`](https://nodejs.org/api/util.html#util_util_inspect_defaultoptions) to the desired depth, before the test is executed: ```js -import test from 'ava'; -import util from 'util'; // import the "util" module from Node.js +import util from 'util'; -util.inspect.defaultOptions.depth = 5; // set the depth +import test from 'ava'; -... +util.inspect.defaultOptions.depth = 5; // Increase AVA's printing depth -test("My test", ...); +test('My test', t => { + t.deepEqual(someDeeplyNestedObject, theExpectedValue); +}); ``` -The minimum object printing depth is 3. If it's set lower than 3, Ava will still print 3 levels of nested objects. +AVA has a minimum depth of `3`.