Skip to content

Commit

Permalink
Merge pull request #420 from inadarei/global-depth-env-var
Browse files Browse the repository at this point in the history
[New] use `process.env.NODE_TAPE_OBJECT_PRINT_DEPTH` for the default object print depth
  • Loading branch information
ljharb committed Jan 15, 2018
2 parents 0e870c6 + 17276d7 commit f26375c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/test.js
Expand Up @@ -8,6 +8,7 @@ var trim = require('string.prototype.trim');
var bind = require('function-bind');
var forEach = require('for-each');
var isEnumerable = bind.call(Function.call, Object.prototype.propertyIsEnumerable);
var toLowerCase = bind.call(Function.call, String.prototype.toLowerCase);

module.exports = Test;

Expand Down Expand Up @@ -52,11 +53,22 @@ function Test (name_, opts_, cb_) {
this.pendingCount = 0;
this._skip = args.opts.skip || false;
this._timeout = args.opts.timeout;
this._objectPrintDepth = args.opts.objectPrintDepth || 5;
this._plan = undefined;
this._cb = args.cb;
this._progeny = [];
this._ok = true;
var depthEnvVar = process.env.NODE_TAPE_OBJECT_PRINT_DEPTH;
if (args.opts.objectPrintDepth) {
this._objectPrintDepth = args.opts.objectPrintDepth;
} else if (depthEnvVar) {
if (toLowerCase(depthEnvVar) === 'infinity') {
this._objectPrintDepth = Infinity;
} else {
this._objectPrintDepth = depthEnvVar;
}
} else {
this._objectPrintDepth = 5;
}

for (var prop in this) {
this[prop] = (function bind(self, val) {
Expand Down
5 changes: 3 additions & 2 deletions readme.markdown
Expand Up @@ -148,8 +148,9 @@ Available `opts` options are:
- opts.timeout = 500. Set a timeout for the test, after which it will fail.
See test.timeoutAfter.
- opts.objectPrintDepth = 5. Configure max depth of expected / actual object
printing.

printing. Environmental variable `NODE_TAPE_OBJECT_PRINT_DEPTH` can set the
desired default depth for all tests; locally-set values will take precedence.

If you forget to `t.plan()` out how many assertions you are going to run and you
don't call `t.end()` explicitly, your test will hang.

Expand Down

0 comments on commit f26375c

Please sign in to comment.