-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: added common.mustCallAtLeast
#12935
Conversation
test/common/index.js
Outdated
/** | ||
* @function mustCall | ||
* @param fn "The code that must be called | ||
* @param {?number|string} expected "Expected times to be called, or '+' for more then 0. Default = 1" |
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.
typo: then → than
CI: https://ci.nodejs.org/job/node-test-commit/9765/ |
test/common/index.js
Outdated
* @returns {Function} | ||
* @export | ||
*/ | ||
exports.mustCall = function mustCall(fn, expected) { |
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 you undo this block of 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.
the JSDocs?
It's usefull for people with IDEs that can parse these (VSCode / Webstorm)
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.
Other than lib/punycode.js
which is vendored, there are only 9 @param
matches in all of lib, src, and test. It's more consistent to drop them.
test/parallel/test-test-common.js
Outdated
@@ -0,0 +1,16 @@ | |||
'use strict'; |
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 code should live in test/parallel/test-common.js
I think.
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.
didn't see that one...
I think this needs a documentation update. |
Docs added, nit's addressed. @cjihrig I'd rather keep the JSDocs, unless you have a strong objection. |
I wouldn't say strong objection, but definitely -1. |
Gone. |
Could you point to somewhere that this would be better suited for rather than the explicit number of calls? |
I generally think this is a bad idea because if something is being called more times than you expect you've probably got a bug. |
|
I tend to agree, but some things are either OS dependent or non deterministic. In those cases we tend to skip the |
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 been wanting this for a while. Once @cjihrig is happy with it, I'm LGTM
-1 I don't think it is a good idea to reuse the same parameter (or even the same function) for this. |
@Fishrock123 ... this came up with regards to adding @mscdex ... the other option I had in mind was a |
@jasnell I would much prefer a separate method so that the intention is clear. |
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.
-0 from me. I dislike magic values. I prefer that things in common
have simple, self-explanatory, and intuitively obvious interfaces. This adds more cognitive overhead, especially for newcomers.
test/common/README.md
Outdated
fail. | ||
Returns a function that calls `fn`. If the returned function has not been | ||
called exactly `expected` number of times, or at least once if | ||
`expected === '+'`, when the test is complete, then the test will fail. |
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.
Nit: This documentation change results in a confusing run-on sentence:
If the returned function has not been called exactly
expected
number of times, or at least once if
expected === '+'
, when the test is complete, then the test will fail.
Would be better as something like:
If the returned function has not been called exactly
expected
number of times when the test is complete, then the test will fail. Ifexpected is
'+'`, then the test must run at least once.
Eh, still pretty +/-0 on it. I think there's enough API surface area in Moreover, I'm not really sure this is solving a very common problem. I imagine it's mostly for But if others feel this has big value, I won't stop it. |
Replace magic '+' with |
expected
common.mustCallAtLeast
P.S. why don't we adopt something like |
Biggest reason is probably because no one's bothered to do it yet. That said, a PR adding sinon very well might not get accepted. Speaking only for myself, I have grown wary of things that raise the barrier to entry for people working on tests. So to the extent that we avoid extra tools and unneeded abstractions in the Others in @nodejs/testing might have other opinions. |
Pre land CI: https://ci.nodejs.org/job/node-test-commit/10013/ |
landed in fccc0bf |
Should this land on v6.x? |
Sure. It's a |
#14327 depends on this |
PR-URL: #12935 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #12935 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
added
common.mustCallAtLeast
for calling more thanminimum
times.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test