Skip to content

Commit f26375c

Browse files
authored
Merge pull request #420 from inadarei/global-depth-env-var
[New] use `process.env.NODE_TAPE_OBJECT_PRINT_DEPTH` for the default object print depth
2 parents 0e870c6 + 17276d7 commit f26375c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var trim = require('string.prototype.trim');
88
var bind = require('function-bind');
99
var forEach = require('for-each');
1010
var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);
11+
var toLowerCase = bind.call(Function.call, String.prototype.toLowerCase);
1112

1213
module.exports = Test;
1314

@@ -52,11 +53,22 @@ function Test (name_, opts_, cb_) {
5253
this.pendingCount = 0;
5354
this._skip = args.opts.skip || false;
5455
this._timeout = args.opts.timeout;
55-
this._objectPrintDepth = args.opts.objectPrintDepth || 5;
5656
this._plan = undefined;
5757
this._cb = args.cb;
5858
this._progeny = [];
5959
this._ok = true;
60+
var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH;
61+
if (args.opts.objectPrintDepth) {
62+
this._objectPrintDepth = args.opts.objectPrintDepth;
63+
} else if (depthEnvVar) {
64+
if (toLowerCase(depthEnvVar) === 'infinity') {
65+
this._objectPrintDepth = Infinity;
66+
} else {
67+
this._objectPrintDepth = depthEnvVar;
68+
}
69+
} else {
70+
this._objectPrintDepth = 5;
71+
}
6072

6173
for (var prop in this) {
6274
this[prop] = (function bind(self, val) {

readme.markdown

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ Available `opts` options are:
148148
- opts.timeout = 500. Set a timeout for the test, after which it will fail.
149149
See test.timeoutAfter.
150150
- opts.objectPrintDepth = 5. Configure max depth of expected / actual object
151-
printing.
152-
151+
printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the
152+
desired default depth for all tests; locally-set values will take precedence.
153+
153154
If you forget to `t.plan()` out how many assertions you are going to run and you
154155
don't call `t.end()` explicitly, your test will hang.
155156

0 commit comments

Comments
 (0)