-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: improve zlib tests #55716
base: main
Are you sure you want to change the base?
test: improve zlib tests #55716
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55716 +/- ##
==========================================
- Coverage 88.42% 88.40% -0.02%
==========================================
Files 654 654
Lines 187662 187763 +101
Branches 36118 36127 +9
==========================================
+ Hits 165945 165999 +54
- Misses 14955 15006 +51
+ Partials 6762 6758 -4 |
8b49cae
to
e337280
Compare
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'm fine with removing redundant tests but I'm -1 on using node:test
as much as we can as per #54796 and #55110 (review). In my opinion this is not an improvement, but added complexity and spurious code executed as part of the test, which could also affect the reliability of the test itself.
const { promise, resolve } = Promise.withResolvers(); | ||
zlib.deflate(inputString, (err, buffer) => { | ||
assert.ifError(err); | ||
zlib.inflate(buffer, (err, inflated) => { | ||
assert.ifError(err); | ||
assert.strictEqual(inflated.toString(), inputString); | ||
resolve(); | ||
}); | ||
}); | ||
await promise; |
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 love how Promise.withResolvers()
helps making callback tests relatively concise, but I don't see how this is better than using common.mustSucceed()
:
const { promise, resolve } = Promise.withResolvers(); | |
zlib.deflate(inputString, (err, buffer) => { | |
assert.ifError(err); | |
zlib.inflate(buffer, (err, inflated) => { | |
assert.ifError(err); | |
assert.strictEqual(inflated.toString(), inputString); | |
resolve(); | |
}); | |
}); | |
await promise; | |
zlib.deflate(inputString, common.mustSucceed((buffer) => { | |
zlib.inflate(buffer, common.mustSucceed((inflated) => { | |
assert.strictEqual(inflated.toString(), inputString); | |
})); | |
})); |
Is there a reason why we should avoid relying on common
utilities?
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.
common.mustSucceed()
depends on process.on('exit')
hook, whereas Promise.withResolvers()
doesn't.
out.on('end', resolve); | ||
|
||
await promise; |
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.
can't we await once(out, 'end')
?
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.
Yes, definitely! Nice catch. Thanks @targos
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 means replacing a Node.js specific API (common.mustCall()
) with another Node.js specific API (events.once()
). What's the point?
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.
common.mustCall()
depends on process.on('exit')
where we definitely don't need to wait for the process to exit to check the state for this current implementation.
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 but I don't see how it is an improvement. It doesn't change anything for the sake of the test.
e337280
to
c1b6cb1
Compare
Remove several unnecessary zlib tests, and use
node:test
as much as we can. This also avoids calling require('../common') functionality as much as we can.