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

test: Z lib const descriptive failure messages #15977

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions test/parallel/test-zlib-const.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,35 @@ const assert = require('assert');

const zlib = require('zlib');

assert.strictEqual(zlib.constants.Z_OK, 0, 'Z_OK should be 0');
assert.strictEqual(zlib.constants.Z_OK, 0,
[
'Expected Z_OK to be 0;',
`got ${zlib.constants.Z_OK}`
].join(' '));
Copy link
Author

Choose a reason for hiding this comment

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

I'm not a fan of this formatting, but I had to adhere to linter rules; specifically, max line length of 80. I would prefer format like this:

assert.strictEqual(zlib.codes.Z_OK, 0,
          `Z_OK should be immutable. Expected to get 0, got ${zlib.codes.Z_OK}`);

What would folks think about overriding the max-line-length linter rule to 120 characters for this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is what is done in test/parallel/test-require-extensions-same-filename-as-dir-trailing-slash.js by adding /* eslint-disable max-len */.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, nice. That's what I had in mind to do. Guess I didn't want to rock the linting rules boat on my first contribution to Node, eh? Ha! Will override here.

Copy link
Member

Choose a reason for hiding this comment

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

This would also work

assert.strictEqual(
  zlib.constants.Z_OK,
  0,
  `Expected Z_OK to be 0; got ${zlib.constants.Z_OK}`
);

Deactiviating the max-len is not a good idea.

zlib.constants.Z_OK = 1;
assert.strictEqual(zlib.constants.Z_OK, 0, 'Z_OK should be 0');
assert.strictEqual(zlib.constants.Z_OK, 0,
[
'Z_OK should be immutable.',
`Expected to get 0, got ${zlib.constants.Z_OK}`
].join(' '));

assert.strictEqual(zlib.codes.Z_OK, 0, 'Z_OK should be 0');
assert.strictEqual(zlib.codes.Z_OK, 0,
`Expected Z_OK to be 0; got ${zlib.codes.Z_OK}`);
zlib.codes.Z_OK = 1;
assert.strictEqual(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0');
assert.strictEqual(zlib.codes.Z_OK, 0,
[
'Z_OK should be immutable.',
`Expected to get 0, got ${zlib.codes.Z_OK}`
].join(' '));
zlib.codes = { Z_OK: 1 };
assert.strictEqual(zlib.codes.Z_OK, 0, 'zlib.codes.Z_OK should be 0');
assert.strictEqual(zlib.codes.Z_OK, 0,
[
'Z_OK should be immutable.',
`Expected to get 0, got ${zlib.codes.Z_OK}`
].join(' '));

assert.ok(Object.isFrozen(zlib.codes), 'zlib.codes should be frozen');
assert.ok(Object.isFrozen(zlib.codes),
[
'Expected zlib.codes to be frozen, but Object.isFrozen',
`returned ${Object.isFrozen(zlib.codes)}`
].join(' '));