-
-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New] use process.env.NODE_TAPE_OBJECT_PRINT_DEPTH
for the default object print depth
#420
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contains a doc change only; there's no functionality change included?
readme.markdown
Outdated
@@ -15,10 +15,10 @@ var test = require('tape'); | |||
|
|||
test('timing test', function (t) { | |||
t.plan(2); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert unrelated whitespace changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, yeah, I was just looking into how to stop VS Code from adding those :)
…object print depth.
lib/results.js
Outdated
if (process.env[depthEnvVar].toLowerCase() === 'infinity') { | ||
res.objectPrintDepth = Infinity; | ||
} else { | ||
res.objectPrintDepth = parseInt(process.env[envVarDepth]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should have an explicit radix (, 10
) for older envs
readme.markdown
Outdated
@@ -148,7 +148,8 @@ 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 depth for all tests and overrides any locally-set values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this override? or should the env var merely set the default, so that local intentional overrides still take precedence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was wondering the same, since good arguments can be made for both approaches. Finally decided to go the current route because:
- seems more compatible with 12-Factor Apps guidance
- env vars overriding is how https://www.npmjs.com/package/config works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've no interest in complying with "12-factor apps" by itself; if it isn't the best thing for the project, then it shouldn't be done.
In general, i would agree that an env var should always override an equivalent setting - but there is no equivalent for "set every object print depth" in tape. Currently, every one is per-test, and per-test overrides imo should always take precedence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, no problem. That makes sense. I was just explaining the logic behind the initial decision, but not doing it that way also makes sense. I will make the change as you requested.
lib/test.js
Outdated
this._plan = undefined; | ||
this._cb = args.cb; | ||
this._progeny = []; | ||
this._ok = true; | ||
var depthEnvVar = 'NODE_TAPE_OBJECT_PRINT_DEPTH'; | ||
if (args.opts.objectPrintDepth) { | ||
this._objectPrintDepth = args.opts.objectPrintDepth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is missing a semicolon
lib/test.js
Outdated
var depthEnvVar = 'NODE_TAPE_OBJECT_PRINT_DEPTH'; | ||
if (args.opts.objectPrintDepth) { | ||
this._objectPrintDepth = args.opts.objectPrintDepth | ||
} else if (process.env[depthEnvVar]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of storing the key name in a variable, and extracting it multiple times, can we just extract the value into a variable right off the bat?
lib/test.js
Outdated
if (args.opts.objectPrintDepth) { | ||
this._objectPrintDepth = args.opts.objectPrintDepth | ||
} else if (process.env[depthEnvVar]) { | ||
if (process.env[depthEnvVar].toLowerCase() === 'infinity') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should try to be robust against delete String.prototype.toLowerCase && delete RegExp.prototype.test
(by caching the prototype method at module level)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I am not sure I understand what you are proposing.
lib/test.js
Outdated
if (process.env[depthEnvVar].toLowerCase() === 'infinity') { | ||
this._objectPrintDepth = Infinity; | ||
} else { | ||
this._objectPrintDepth = parseInt(process.env[depthEnvVar], 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, i'm not actually sure about the parseInt here. tape doesn't seem to do any typechecking on the objectPrintDepth
option - ie, you could pass a non-number or a non-integer and it'd just coerce to a number later. Maybe we should do the same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
lib/test.js
Outdated
@@ -56,14 +56,14 @@ function Test (name_, opts_, cb_) { | |||
this._cb = args.cb; | |||
this._progeny = []; | |||
this._ok = true; | |||
var depthEnvVar = 'NODE_TAPE_OBJECT_PRINT_DEPTH'; | |||
var depthEnvVar = process.env['NODE_TAPE_OBJECT_PRINT_DEPTH'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please always use dot access instead of bracket access in javascript wherever possible.
lib/test.js
Outdated
if (args.opts.objectPrintDepth) { | ||
this._objectPrintDepth = args.opts.objectPrintDepth; | ||
} else if (depthEnvVar) { | ||
if (depthEnvVar.toLowerCase() === 'infinity') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify: we should have var toLowerCase = String.prototype.toLowerCase;
near the top of the file, and then here, do toLowerCase.call(depthEnvVar)
instead of assuming that nobody's done delete String.prototype.toLowerCase
inside their tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the approval and assitance in getting there. What are the next steps for a merge? |
process.env.NODE_TAPE_OBJECT_PRINT_DEPTH
for the default object print depth
- [New] use `process.env.NODE_TAPE_OBJECT_PRINT_DEPTH` for the default object print depth (#420) - [New] Add "onFailure" listener to test harness (#408) - [Fix] fix stack where actual is falsy (#400) - [Fix] normalize path separators in stacks (#402) - [Fix] fix line numbers in stack traces from inside anon functions (#387) - [Fix] Fix dirname in stack traces (#388) - [Robustness] Use local reference for clearTimeout global (#385) - [Deps] update `function-bind`
Issue #419