-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Improve testing functionality #2858
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e988cff
Minimal testing functionality
WorldSEnder 26798b7
remove rust version from crate, serves no purpose
WorldSEnder 637fd0d
enable tests only with target_arch wasm
WorldSEnder aff76e0
fix clippy feature soundness lints
WorldSEnder 4fd88e6
fix doc tests
WorldSEnder d02e0bd
Merge remote-tracking branch 'upstream/master' into testing-v2
WorldSEnder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| [package] | ||
| name = "yew-test-runner" | ||
| version = "0.19.0" | ||
| edition = "2021" | ||
| authors = [ | ||
| "Martin Molzer <WorldSEnder@users.noreply.github.com>", | ||
| ] | ||
| repository = "https://github.com/yewstack/yew" | ||
| homepage = "https://github.com/yewstack/yew" | ||
| documentation = "https://docs.rs/yew/" | ||
| license = "MIT OR Apache-2.0" | ||
| keywords = ["web", "webasm", "javascript"] | ||
| categories = ["gui", "wasm", "web-programming"] | ||
| description = "A framework for testing client-side single-page apps" | ||
| readme = "./README.md" | ||
|
|
||
| [dependencies] | ||
| gloo = "0.8" | ||
| tracing = "0.1.36" | ||
| yew = { version = "0.19", path = "../yew", features = ["csr"] } | ||
|
|
||
| [dependencies.web-sys] | ||
| version = "^0.3.59" | ||
|
|
||
| [dev-dependencies] | ||
| wasm-bindgen-test = "0.3" | ||
|
|
||
| [features] | ||
| default = ["hydration"] | ||
| hydration = ["yew/ssr", "yew/hydration"] | ||
|
|
||
| [package.metadata.docs.rs] | ||
| all-features = true | ||
| rustdoc-args = ["--cfg", "documenting"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| [tasks.wasm-test] | ||
| command = "wasm-pack" | ||
| args = [ | ||
| "test", | ||
| "--firefox", | ||
| "--headless", | ||
| "--", | ||
| "--all-features", | ||
| ] | ||
|
|
||
| [tasks.test] | ||
| args = ["test", "--all-targets", "--all-features"] | ||
| dependencies = ["wasm-test"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <div align="center"> | ||
| <img src="https://yew.rs/img/logo.png" width="150" /> | ||
|
|
||
| <h1>Yew Test Runner</h1> | ||
|
|
||
| <p> | ||
| <strong>Testing framework for Yew components</strong> | ||
| </p> | ||
|
|
||
| <p> | ||
| <a href="https://crates.io/crates/yew-test-runner"><img alt="Crate Info" src="https://img.shields.io/crates/v/yew.svg"/></a> | ||
| <a href="https://docs.rs/yew-test-runner/"><img alt="API Docs" src="https://img.shields.io/badge/docs.rs-yew-green"/></a> | ||
| <a href="https://discord.gg/VQck8X4"><img alt="Discord Chat" src="https://img.shields.io/discord/701068342760570933"/></a> | ||
| </p> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| //! Snapshot testing of Yew components | ||
|
|
||
| use yew::virtual_dom::VNode; | ||
| use yew::{Html, Renderer}; | ||
|
|
||
| use crate::scaffold::{TestScaffold, TestScaffoldProps}; | ||
|
|
||
| #[derive(Debug)] | ||
| pub struct TestLayout<'a> { | ||
| pub name: &'a str, | ||
| pub node: VNode, | ||
| pub expected: &'a str, | ||
| } | ||
|
|
||
| pub fn diff_layouts(layouts: Vec<TestLayout<'_>>) { | ||
| let document = gloo::utils::document(); | ||
| let parent_element = document.create_element("div").unwrap(); | ||
|
|
||
| // start with empty children | ||
| let mut test_host = Renderer::<TestScaffold>::with_root(parent_element.clone()).render(); | ||
| yew::scheduler::__unstable_start_now(); | ||
|
|
||
| // Tests each layout independently | ||
| for layout in layouts.iter() { | ||
| // Apply the layout | ||
| tracing::debug!(name = layout.name, "Independently apply layout"); | ||
|
|
||
| let vnode = layout.node.clone(); | ||
| test_host.update(TestScaffoldProps { test_case: vnode }); | ||
| yew::scheduler::__unstable_start_now(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| format!("{}", layout.expected), | ||
| "Independent apply failed for layout '{}'", | ||
| layout.name, | ||
| ); | ||
|
|
||
| // Diff with no changes | ||
| tracing::debug!(name = layout.name, "Independently reapply layout"); | ||
|
|
||
| let vnode = layout.node.clone(); | ||
| test_host.update(TestScaffoldProps { test_case: vnode }); | ||
| yew::scheduler::__unstable_start_now(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| format!("{}", layout.expected), | ||
| "Independent reapply failed for layout '{}'", | ||
| layout.name, | ||
| ); | ||
|
|
||
| // Detach | ||
| test_host.update(TestScaffoldProps { | ||
| test_case: Html::default(), | ||
| }); | ||
| yew::scheduler::__unstable_start_now(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| "", | ||
| "Independent detach failed for layout '{}'", | ||
| layout.name, | ||
| ); | ||
| } | ||
|
|
||
| // Sequentially apply each layout | ||
| for layout in layouts.iter() { | ||
| tracing::debug!(name = layout.name, "Sequentially apply layout"); | ||
|
|
||
| let vnode = layout.node.clone(); | ||
| test_host.update(TestScaffoldProps { test_case: vnode }); | ||
| yew::scheduler::__unstable_start_now(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| format!("{}", layout.expected), | ||
| "Sequential apply failed for layout '{}'", | ||
| layout.name, | ||
| ); | ||
| } | ||
|
|
||
| // Sequentially detach each layout | ||
| for layout in layouts.into_iter().rev() { | ||
| let vnode = layout.node.clone(); | ||
|
|
||
| tracing::debug!(name = layout.name, "Sequentially detach layout"); | ||
| test_host.update(TestScaffoldProps { test_case: vnode }); | ||
| yew::scheduler::__unstable_start_now(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| format!("{}", layout.expected), | ||
| "Sequential detach failed for layout '{}'", | ||
| layout.name, | ||
| ); | ||
| } | ||
|
|
||
| // Detach last layout | ||
| test_host.destroy(); | ||
| assert_eq!( | ||
| parent_element.inner_html(), | ||
| "", | ||
| "Failed to detach last layout" | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //! Yew test runner | ||
|
|
||
| pub mod layout_tests; | ||
| pub mod procedural; | ||
| mod scaffold; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_layoutsdoes, 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
IntoIteratorwould be better.This will allow the following to compile: