Skip to content
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

Merged
merged 1 commit into from
Jan 15, 2018
Merged

[New] use process.env.NODE_TAPE_OBJECT_PRINT_DEPTH for the default object print depth #420

merged 1 commit into from
Jan 15, 2018

Conversation

inadarei
Copy link
Contributor

@inadarei inadarei commented Jan 2, 2018

Issue #419

Copy link
Collaborator

@ljharb ljharb left a 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);

Copy link
Collaborator

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.

Copy link
Contributor Author

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 :)

lib/results.js Outdated
if (process.env[depthEnvVar].toLowerCase() === 'infinity') {
res.objectPrintDepth = Infinity;
} else {
res.objectPrintDepth = parseInt(process.env[envVarDepth]);
Copy link
Collaborator

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.
Copy link
Collaborator

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?

Copy link
Contributor Author

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:

  1. seems more compatible with 12-Factor Apps guidance
  2. env vars overriding is how https://www.npmjs.com/package/config works

Copy link
Collaborator

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.

Copy link
Contributor Author

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
Copy link
Collaborator

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]) {
Copy link
Collaborator

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') {
Copy link
Collaborator

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)

Copy link
Contributor Author

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);
Copy link
Collaborator

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?

Copy link
Contributor Author

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']
Copy link
Collaborator

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') {
Copy link
Collaborator

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.

Copy link
Collaborator

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@inadarei
Copy link
Contributor Author

Thanks for the approval and assitance in getting there. What are the next steps for a merge?

@ljharb ljharb changed the title Allow Setting opts.objectPrintDepth Globally [New] use process.env.NODE_TAPE_OBJECT_PRINT_DEPTH for the default object print depth Jan 15, 2018
@ljharb ljharb merged commit f26375c into tape-testing:master Jan 15, 2018
@inadarei inadarei deleted the global-depth-env-var branch January 15, 2018 20:56
ljharb added a commit that referenced this pull request Feb 19, 2018
 - [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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants