-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Improve testing functionality #2858
base: master
Are you sure you want to change the base?
Conversation
Visit the preview URL for this PR (updated for commit d02e0bd): https://yew-rs-api--pr2858-testing-v2-cvc0aw2k.web.app (expires Mon, 19 Sep 2022 01:54:34 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
Can you try adding the new crate as a dependency in Yew? I don't think it can be used for Yew tests because of circular dependency |
Adding it as a Also relevant is rust-lang/cargo#6765 (comment), which explains how this is allowed. Note that external tests, such as in the |
pub expected: &'a str, | ||
} | ||
|
||
pub fn diff_layouts(layouts: Vec<TestLayout<'_>>) { |
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 add documentation here for what diff_layouts
does, steps it goes through and an example on how to use it?
Module level documentation for those who are unfamiliar with layout/snapshot testing would be good to have as well. We don't need to thoroughly explain what it is, a link to somewhere that explains it well alongside a short summary would be enough
Also, changing the signature to accept IntoIterator
would be better.
pub fn diff_layouts(layouts: Vec<TestLayout<'_>>) { | |
pub fn diff_layouts<'a>(layouts: impl IntoIterator<Item = TestLayout<'a>>) { |
This will allow the following to compile:
diff_layouts([layout]);
diff_layouts(vec![layout]);
|
||
/// Helper trait for things that can be more-or-less treated as a [`TestRunner`]. | ||
/// | ||
/// Automatically gets an implementation of [`TestCase`]. |
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.
/// Automatically gets an implementation of [`TestCase`]. | |
/// Automatically gets an implementation of [`TestRunner`]. |
I think you meant TestRunner
, not TestCase
/// Common methods to [`TestRunner`] and [`TestStep`]. Automatically implemented for any type | ||
/// implementing [`TestContext`]. |
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 methods to [`TestRunner`] and [`TestStep`]. Automatically implemented for any type | |
/// implementing [`TestContext`]. | |
/// Common methods to [`TestRunner`] and [`TestStep`]. | |
/// | |
/// Automatically implemented for any type implementing [`TestContext`]. |
Just formatting. This helps rustdoc only display the important line on the home page
@@ -0,0 +1,306 @@ | |||
//! A procedural style setup for a test runner |
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.
See documentation part of #2858 (comment)
There's many of them that use layout test. Wouldn't those break? |
I think there are 3 areas that this new testing API needs to improve if we want to endorse it for component testing of user authored crates: Tests are synchronousAsynchronous events and network requests are prevalent in a web application and tests usually need to accommodate them. These require tests to run asynchronously. However, both procedural and layout tests are running tests synchronously. Tests fail as soon as an assertion fails onceHistorically, large number of Selenium tests are difficult to maintain and intermittently fails because they would fail as soon as a test command fails an assertion once. Modern testing frameworks (Cypress, Playwright, react-testing-library, etc.) usually operates asynchronously by retrying testing operation in a short interval until either the test command times out or it becomes successful. Tests are encouraged to assert the entire rendered content of a componentThis behaviour might be more desirable if we are verifying the behaviour of the Yew renderer. However, asserting all contents might not be as desirable when used to verify user defined components. There are 2 reasons:
|
Description
This PR contains a nyew crate,
yew-test-runner
, that exposes component testing functionality. It re-implementslayout_tests
with only public API and has aprocedural
API. The focus should be on the latter, as I think it's more principled and leads to more readable test code, and can be more easily expanded to further functionality.The reason to have a separate crate is to decouple releases and added functionality, on top of dog feeding our own API. For example, I've had to add a
__unstable_start_now
function to the scheduler to get it to work. Unstable until further consensus on its meaning. A further argument to have a separate crate is that a module exposed only with#[cfg(test)]
is weird and doesn't show up in cargo docs. Adding a feature flag enabling testing code would somewhat complicate internal tests.Open questions and issues:
__unstable_start_now
could be stable, but in this case, should it panic when the scheduler is already active (and it's not actually doing something?). Should it guarantee that all current events were consumed or is it a "best effort to make some progress"?Subsumes the testing API in #2679, internal tests are not converted (yet). It's much smaller and easier to review.
Checklist