wip: Makefile setup

This commit is contained in:
t1m0t 2022-02-01 20:40:29 +01:00
parent e02dfc3324
commit d7968c987f
4 changed files with 148 additions and 28 deletions

42
Makefile.toml Normal file
View file

@ -0,0 +1,42 @@
[config]
default_to_workspace = false
min_version = "0.32.4"
[env]
CARGO_MAKE_CLIPPY_ARGS = "-- --deny=warnings"
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
[config.modify_core_tasks]
namespace = "core"
private = true
[tasks.tests]
category = "Testing"
dependencies = ["tests-setup"]
description = "Run all tests"
env = {CARGO_MAKE_WORKSPACE_SKIP_MEMBERS = ["**/examples/*", "**/packages/changelog"]}
run_task = {name = ["test-flow"], fork = true}
[tasks.tests-setup]
private = true
script = [
"""
test_flags = array --headless --firefox
dioxus_test_features = set wasm_test
dioxus_test_flags = array_join ${test_flags} " "
echo "running tests with flags: ${dioxus_test_flags} and features: ${dioxus_test_features}"
set_env DIOXUS_TEST_FLAGS ${dioxus_test_flags}
set_env DIOXUS_TEST_FEATURES ${dioxus_test_features}
""",
]
script_runner = "@duckscript"
[tasks.test-flow]
dependencies = ["test"]
private = true
workspace = true
[tasks.test]
args = ["test", "--all-targets"]
command = "cargo"
private = true

View file

@ -1,25 +1,29 @@
[package]
name = "dioxus-router"
version = "0.1.1"
edition = "2018"
description = "Dioxus VirtualDOM renderer for the web browser using websys"
license = "MIT/Apache-2.0"
repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com"
documentation = "https://dioxuslabs.com"
edition = "2018"
homepage = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react", "wasm"]
license = "MIT/Apache-2.0"
name = "dioxus-router"
repository = "https://github.com/DioxusLabs/dioxus/"
version = "0.1.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dioxus-core = {path = "../core", version = "^0.1.9", default-features = false}
dioxus-html = { path = "../html", version = "^0.1.6", default-features = false }
dioxus-core-macro = {path = "../core-macro", version = "^0.1.7"}
dioxus-html = {path = "../html", version = "^0.1.6", default-features = false}
serde = "1"
url = "2.2.2"
serde_urlencoded = "0.7"
url = "2.2.2"
# for wasm
gloo = {version = "0.5", optional = true}
js-sys = {version = "0.3", optional = true}
log = "0.4.14"
wasm-bindgen = {version = "0.2", optional = true}
web-sys = {version = "0.3", features = [
"Attr",
"Document",
@ -31,21 +35,17 @@ web-sys = { version = "0.3", features = [
"UrlSearchParams",
"Window",
], optional = true}
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
gloo = { version = "0.5", optional = true }
log = "0.4.14"
[features]
default = ["derive", "web"]
web = ["web-sys", "gloo", "js-sys", "wasm-bindgen"]
derive = []
desktop = []
mobile = []
derive = []
web = ["web-sys", "gloo", "js-sys", "wasm-bindgen"]
[dev-dependencies]
console_error_panic_hook = "0.1.7"
dioxus-web = {path = "../web"}
log = "0.4.14"
wasm-bindgen-test = "0.3"
wasm-logger = "0.2.0"

View file

@ -0,0 +1,10 @@
[tasks.test]
args = [
"test",
"@@split(DIOXUS_TEST_FLAGS, )",
"--",
"--features",
"${DIOXUS_TEST_FEATURES}",
]
command = "wasm-pack"
extend = "core::wasm-pack-base"

View file

@ -0,0 +1,68 @@
#![cfg(target_arch = "wasm32")]
use dioxus_core::prelude::*;
use dioxus_core_macro::*;
use dioxus_html as dioxus_elements;
use dioxus_router::*;
use gloo_utils::document;
use serde::{Deserialize, Serialize};
use wasm_bindgen_test::*;
wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test]
fn simple_test() {
fn main() {
console_error_panic_hook::set_once();
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
dioxus_web::launch(APP);
}
static APP: Component = |cx| {
cx.render(rsx! {
Router {
onchange: move |route| log::info!("route changed to {}", route),
Route { to: "/", Home {} }
Route { to: "blog"
Route { to: "/", BlogList {} }
Route { to: ":id", BlogPost {} }
}
}
})
};
fn Home(cx: Scope) -> Element {
cx.render(rsx! {
div {
h1 { "Home" }
}
})
}
fn BlogList(cx: Scope) -> Element {
cx.render(rsx! {
div {
}
})
}
fn BlogPost(cx: Scope) -> Element {
let id = use_route(&cx).segment::<usize>("id")?;
cx.render(rsx! {
div {
id: "test1",
id
}
})
}
main();
let element = gloo_utils::document()
.get_element_by_id("test1")
.expect("No result found. Most likely, the application crashed")
.inner_html();
assert!(element, "");
}