Merge pull request #190 from t1m0t/tb/makefile_test_setup

wip: Makefile setup
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-02-03 12:49:06 -05:00
commit 76ccd49719
14 files changed
+244 -4

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
FROM rust:1.58-buster
RUN apt update
RUN apt install -y libglib2.0-dev libgtk-3-dev libsoup2.4-dev libappindicator3-dev libwebkit2gtk-4.0-dev firefox-esr
RUN cargo install cargo-make --debug
RUN cargo install cargo-cache && cargo cache -a
CMD ["echo","\"base image built\""]
+8
View File
@@ -0,0 +1,8 @@
FROM dioxus-base-test-image
RUN mkdir run_test
COPY tmp /run_test
WORKDIR /run_test
RUN cargo make tests
CMD ["exit"]
+27
View File
@@ -0,0 +1,27 @@
# Why this?
This part is used to test whole package before pushing it
# How to use it?
Just run in the folder:
`bash run_local_tests.sh`. If nothing fails, then you can push your code to the repo.
or run:
`bash run_local_tests.sh --with-full-docker-cleanup`
for cleaning up images as well
# How is it composed of?
1. `Dockerfile_pre_test` will build the base image for the tests to be run into
2. `Dockerfile_test` will run the actual tests based on 1.
3. `run_local_tests.sh` to wrap this up
# Warning
The task requires some amount of CPU work and disk space (5GB per tests). Some clean up is included in the script.
# Requirements
* [docker](https://docs.docker.com/engine/install/)
* bash
* rsync
+38
View File
@@ -0,0 +1,38 @@
set -eux
echo "Test script started"
function run_script {
if [[ -d tmp ]]
then
rm -rf tmp
fi
mkdir tmp
# copy files first
rsync -a --progress ../ tmp --exclude target --exclude docker
# build base image
docker build -f Dockerfile_pre_test -t dioxus-base-test-image .
# run test
docker build -f Dockerfile_test -t dioxus-test-image .
# clean up
rm -rf tmp
if [ $# -ge 1 ]
then
echo "Got some parameter"
if [ $1 = "--with-full-docker-cleanup" ]
then
docker image rm dioxus-base-test-image
docker image rm dioxus-test-image
docker system prune -af
fi
fi
}
run_script || echo "Error occured.. cleaning a bit." && \
docker system prune -af;
docker system prune -af
echo "Script finished to execute"
+9 -3
View File
@@ -33,10 +33,16 @@ jobs:
- uses: Swatinem/rust-cache@v1
- run: sudo apt-get update
- run: sudo apt install libwebkit2gtk-4.0-dev libappindicator3-dev libgtk-3-dev
- uses: actions-rs/cargo@v1
- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: test
args: --features "desktop, ssr, router"
command: install
args: --debug cargo-make
- uses: actions-rs/cargo@v1
- uses: browser-actions/setup-firefox@latest
with:
command: make
args: tests
fmt:
name: Rustfmt
+4
View File
@@ -4,4 +4,8 @@
"desktop",
"router"
],
"editor.formatOnSave": true,
"[toml]": {
"editor.formatOnSave": false
}
}
+42
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", "--workspace", "--exclude", "dioxus-mobile"]
command = "cargo"
private = true
+2 -1
View File
@@ -1,4 +1,4 @@
use dioxus::prelude::*;
/* use dioxus::prelude::*;
use dioxus_core as dioxus;
use dioxus_core_macro::*;
use dioxus_hooks::*;
@@ -32,3 +32,4 @@ fn app(cx: Scope) -> Element {
}
})
}
*/
+5
View File
@@ -13,3 +13,8 @@ license = "MIT/Apache-2.0"
[dependencies]
dioxus-desktop = { path = "../desktop", version = "^0.1.6" }
[lib]
doctest = false
# tests suspended until package ready
test = false
+7
View File
@@ -0,0 +1,7 @@
[tasks.test]
command = "cargo"
args = [
"test",
"--no-run",
]
+9
View File
@@ -43,9 +43,18 @@ web = ["web-sys", "gloo", "js-sys", "wasm-bindgen"]
desktop = []
mobile = []
derive = []
wasm_test = []
[dev-dependencies]
console_error_panic_hook = "0.1.7"
dioxus-web = { path = "../web" }
log = "0.4.14"
wasm-logger = "0.2.0"
wasm-bindgen-test = "0.3"
gloo-utils = "0.1.2"
[dev-dependencies.web-sys]
version = "0.3"
features = [
"Document",
]
+10
View File
@@ -0,0 +1,10 @@
[tasks.test]
extend = "core::wasm-pack-base"
command = "wasm-pack"
args = [
"test",
"@@split(DIOXUS_TEST_FLAGS, )",
"--",
"--features",
"${DIOXUS_TEST_FEATURES}",
]
+63
View File
@@ -0,0 +1,63 @@
#![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 {
}
})
}
main();
let element = gloo_utils::document();
}
+11
View File
@@ -0,0 +1,11 @@
{
"moz:firefoxOptions": {
"binary": "/usr/bin/firefox",
"prefs": {
"media.navigator.streams.fake": true,
"media.navigator.permission.disabled": true
},
"args": []
}
}