-
Notifications
You must be signed in to change notification settings - Fork 781
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
Core: Add test.each. #1569
Core: Add test.each. #1569
Conversation
I'm really liking this; both with the client-facing API design and it's clean implementation, IMHO. Thanks for your patience in iterating. I agree the exact naming can be left as a follow up; this looks like a solid foundational piece to build up the other support that was discussed. Next, allow objects with field names? Then support "flat" (or idk, "primitive") arrays for convenience? I feel like those should be very near-term though separate follow ups, just to round out the feature. |
Thanks @smcclure15, I just added support of 1D arrays. Let's tackle "objects with field names" as a fast follow up as I would like to discuss a few examples in #1568 first before working on it. @Krinkle FYI. |
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 am in favor of this change; still want to bash it interactively for edge cases, but the design/implementation looks solid.
I defer to @Krinkle as lead for the go/no-go on this.
@Krinkle any chance you might take a look at this? |
Thanks @ventuno and @smcclure15, this is looking good. My main concerns at this point are about making sure the ergonomics hold up in relation to these two things:
By adding It could be a sibling of Another way would be to try to squish it into the So the options would be: 1. This feels a bit out of place in that it isn't a mode of "test" like the other three properties. On the other hand, it is the least disruptive to the API, but placing it in the only "test"-related corner of the API that has precedent for expansion. 2. This is the leanest option and is also least disruptive. It retains the logic that the two main methods are "module" and "test" which together do everything. The two methods both have various aliases of themselves as properties which invoke them in special modes. The downside I see with this is that it might be a bit too lean for less experienced developers, and leaves any form of name for the feature to documentation and social constructs, which also make it harder to search for help. There's also potential for difficult linting / typing when the callback accepts variadic parameters in some cases but not others. For ESLint, I'm not worried about this as it should be trivial to detect the presence of a middle parameter and allow extra arguments based on that. For TypeScript, it has support for overloads, so that seems fine. 3. This one feels structurally correct to me, in that it's not a method that defines a test. Rather, it's a new primitive between "module" and "test" that defines tests on your behalf. The downside is that it breaks the single-object model we have currently, which would make nesting difficult (ref #978). It basically has to be either squished into the "test" method, or be a property of it. 4. Same as "3" but more verbosely named. I was pondering with this, thinking it might sort or look better in the API for discovery and in IDEs. But, would probably be worse long-term, because So, yeah, I think |
@Krinkle: updated the name to append the index prefixed by For example:
Current output with array indexes:
Suggested output:
Suggested output with property names:
|
@ventuno Sounds good, let's go with Actually, using |
Thanks @Krinkle, just updated it. See attached screenshot. |
Thanks! I might do a follow-up to add some spacing in the default theme between |
@Krinkle that sounds good to me. Or we can also address this as part of my next PR to support objects as inputs. I also wanted to get your comments on #1568 (comment) so that I know in which direction to start. |
docs/QUnit/test.each.md
Outdated
categories: | ||
- main | ||
- async | ||
version_added: "1.0" |
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.
Set this to "unreleased"
for now.
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.
Done. Is this going to be updated automatically with a new release?
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.
Not at the moment. I try to remember them, or grep for it, during a release and fill them in as part of the release prep commit. While our release cadence is increasing through past and this year, I don't expect features to accumulate. So, for now, my view of the Is It Worth The Time? table says that it's not worth automating.
Having said that, it seems like a simple thing to automate and so I wouldn't be worried about it complicating our maintenance work. If you feel compelled to give it a try (perhaps as a way to familiarize with the release process), it would likely take the form of an additional step in build/prep-release.js.
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.
Thanks. Let me look into that after #1614.
I'll land this tomorrow after one final closer look. From glancing it over now, I think maybe the added tests aren't actually being run by either test-on-node, nor the grunt/browser test. I may've missed it, but it seems like it's not wired up. If that's indeed the case, I suggest the main each test be added to the main list of tests (via test/index.html and the list of test-on-node tests), and then the special one that has to be its own file (each-only) kept as-is but make sure it is in the list of tests that the grunt/browser task iterates over, if it isn't already included by other means. |
Thanks @Krinkle, take your time. I added |
The default seems to be sorted by filename, which would be good enough if it weren't for the fact that it includes the `.md` file extension, and thus, after we introduced `test.each.md`, the sorting was: * test.each * test * test.only * test.skip * test.todo because `each` < `md`: * test.each.md * test.md * test.only.md * test.skip.md * test.todo.md Fix by adding an explicit sort for the `title` key. Ref #1569.
* Use "data provider" once or twice for better search and discovery. * Refer to the input as `dataset` and each item as `data`. The `args` name, I think, was less obvious in meaning since it is leaning very specifically towards 'data as array' and the destructuring approach (or variadic argument, from an earlier iteration of #1569). * Add verbose form of all only/skip/todo signatures to the intro. * Move the helpful use cases and advice from param table into the description paragraphs. * Split "basic", "array", and "promise" examples up into three separate headings. * Add async function example. Follows-up 07de4b1.
This restores previous behaviour to avoid breaking plugins that might already extend or monkey-patch QUnit to add additional parameters to the test callback. Also: * Declare the params setting in the Test class for added clarity, and to ensure a consistent object shape. * Make more use of the new `addTest()` function that was added in #1569, this reduces a lot of duplication. While at it, I shifted the abstraction slightly to expose the Test class settings directly, thus making the `addTest()` mainly be responsible for the queuing and filtering, and no longer responsible for formatting the Test class settings. The use of ES2015 shorthand property name syntax makes feel almost identical to the function parameter signature.
@@ -674,66 +674,122 @@ function checkPollution() { | |||
} | |||
} | |||
|
|||
function addTestWithData( data ) { |
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 like this abstraction a lot, did you mean to make more use of it? I went ahead and did so as part of #1620.
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 actually came from @smcclure15's recommendation. Glad it's useful!
This restores previous behaviour to avoid breaking plugins that might already extend or monkey-patch QUnit to add additional parameters to the test callback. Also: * Declare the params setting in the Test class for added clarity, and to ensure a consistent object shape. * Make more use of the new `addTest()` function that was added in #1569, this reduces a lot of duplication. While at it, I shifted the abstraction slightly to expose the Test class settings directly, thus making the `addTest()` mainly be responsible for the queuing and filtering, and no longer responsible for formatting the Test class settings. The use of ES2015 shorthand property name syntax makes feel almost identical to the function parameter signature.
WIP implementation of #1568.