From 905d46a09dfe20fe9b5055714a6e3cedf0137b95 Mon Sep 17 00:00:00 2001 From: Joseph Cruz Date: Fri, 8 Sep 2023 07:31:55 -0400 Subject: [PATCH] refactor(examples): extract client process tasks (#1665) (#1666) * doc(test-report): report trunk and node * refactor(examples): extract client process tasks * chore(exaples): force ci --- examples/Makefile.toml | 59 +++++++++---------- examples/README.md | 2 +- examples/cargo-make/cargo-leptos-test.toml | 4 -- .../cargo-leptos-webdriver-test.toml | 7 +++ examples/cargo-make/cargo-leptos.toml | 34 ++--------- examples/cargo-make/client-process.toml | 35 +++++++++++ .../cargo-make/playwright-trunk-test.toml | 4 +- examples/cargo-make/trunk_server.toml | 36 ++--------- examples/suspense_tests/Makefile.toml | 16 +---- examples/tailwind/Makefile.toml | 4 ++ examples/todo_app_sqlite/Makefile.toml | 16 +---- examples/todo_app_sqlite_axum/Makefile.toml | 16 +---- 12 files changed, 96 insertions(+), 137 deletions(-) create mode 100644 examples/cargo-make/cargo-leptos-webdriver-test.toml create mode 100644 examples/cargo-make/client-process.toml diff --git a/examples/Makefile.toml b/examples/Makefile.toml index b15c1fb06..fe69f5517 100644 --- a/examples/Makefile.toml +++ b/examples/Makefile.toml @@ -51,7 +51,7 @@ echo "CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = $examples" [tasks.test-report] workspace = false -description = "report ci test runners and tools for each example - OPTION: [all]" +description = "report web testing technology used by examples - OPTION: [all]" script = ''' set -emu @@ -62,9 +62,7 @@ YELLOW="\e[0;33m" RESET="\e[0m" echo -echo "${YELLOW}Test Report${RESET}" -echo -echo "${ITALIC}Pass the option \"all\" to show all the examples${RESET}" +echo "${YELLOW}Web Test Technology${RESET}" echo makefile_paths=$(find . -name Makefile.toml -not -path '*/target/*' -not -path '*/node_modules/*' | @@ -80,15 +78,7 @@ for path in $makefile_paths; do crate_symbols= - test_count=$(grep -r --exclude-dir=target --exclude-dir=node_modules --fixed-strings "#[test]" | wc -l) - if [ $test_count -gt 0 ]; then - crate_symbols="T" - fi - - rstest_count=$(grep -r --exclude-dir=target --exclude-dir=node_modules --fixed-strings "#[rstest]" | wc -l) - if [ $rstest_count -gt 0 ]; then - crate_symbols=$crate_symbols"R" - fi + pw_count=$(find . -name playwright.config.ts | wc -l) while read -r line; do case $line in @@ -96,22 +86,36 @@ for path in $makefile_paths; do crate_symbols=$crate_symbols"C" ;; *"fantoccini"*) - crate_symbols=$crate_symbols"F" + crate_symbols=$crate_symbols"D" ;; esac done <"./Cargo.toml" while read -r line; do case $line in - *"cargo-make/wasm-test"*) + *"cargo-make/wasm-test.toml"*) crate_symbols=$crate_symbols"W" ;; - *"cargo-make/playwright"*) + *"cargo-make/playwright-test.toml"*) crate_symbols=$crate_symbols"P" + crate_symbols=$crate_symbols"N" ;; - *"cargo-make/cargo-leptos-test"*) + *"cargo-make/playwright-trunk-test.toml"*) + crate_symbols=$crate_symbols"P" + crate_symbols=$crate_symbols"T" + ;; + *"cargo-make/trunk_server.toml"*) + crate_symbols=$crate_symbols"T" + ;; + *"cargo-make/cargo-leptos-webdriver-test.toml"*) crate_symbols=$crate_symbols"L" ;; + *"cargo-make/cargo-leptos-test.toml"*) + crate_symbols=$crate_symbols"L" + if [ $pw_count -gt 0 ]; then + crate_symbols=$crate_symbols"P" + fi + ;; esac done <"./Makefile.toml" @@ -135,20 +139,15 @@ for path in $makefile_paths; do cd ${start_path} done -c="${BOLD}${YELLOW}C${RESET} = Cucumber Test" -f="${BOLD}${YELLOW}F${RESET} = Fantoccini WebDriver" -l="${BOLD}${YELLOW}L${RESET} = Cargo Leptos Test" -p="${BOLD}${YELLOW}P${RESET} = Playwright Test" -r="${BOLD}${YELLOW}R${RESET} = RS Test" -u="${BOLD}${YELLOW}U${RESET} = Unit Test" -w="${BOLD}${YELLOW}W${RESET} = WASM Test" +c="${BOLD}${YELLOW}C${RESET} = Cucumber" +d="${BOLD}${YELLOW}D${RESET} = WebDriver" +l="${BOLD}${YELLOW}L${RESET} = Cargo Leptos" +n="${BOLD}${YELLOW}N${RESET} = Node" +p="${BOLD}${YELLOW}P${RESET} = Playwright" +t="${BOLD}${YELLOW}T${RESET} = Trunk" +w="${BOLD}${YELLOW}W${RESET} = WASM" echo -echo "${ITALIC}Keys:${RESET}\n $c\n $f\n $l\n $p\n $r\n $u\n $w" +echo "${ITALIC}Keys:${RESET} $c, $d, $l, $n, $p, $t, $w" echo ''' - -# ALIASES - -[tasks.tr] -alias = "test-report" diff --git a/examples/README.md b/examples/README.md index d641b1310..33ca2411d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -4,4 +4,4 @@ The examples in this directory are all built and tested against the current `mai To the extent that new features have been released or breaking changes have been made since the previous release, the examples are compatible with the `main` branch and not the current release. -To see the examples as they were at the time of the `0.3.0` release, [click here](https://github.com/leptos-rs/leptos/tree/v0.3.0/examples). \ No newline at end of file +To see the examples as they were at the time of the `0.3.0` release, [click here](https://github.com/leptos-rs/leptos/tree/v0.3.0/examples). diff --git a/examples/cargo-make/cargo-leptos-test.toml b/examples/cargo-make/cargo-leptos-test.toml index 7cb7a7d91..f7499463b 100644 --- a/examples/cargo-make/cargo-leptos-test.toml +++ b/examples/cargo-make/cargo-leptos-test.toml @@ -2,7 +2,3 @@ extend = { path = "./cargo-leptos.toml" } [tasks.integration-test] dependencies = ["install-cargo-leptos", "cargo-leptos-e2e"] - -[tasks.cargo-leptos-e2e] -command = "cargo" -args = ["leptos", "end-to-end"] diff --git a/examples/cargo-make/cargo-leptos-webdriver-test.toml b/examples/cargo-make/cargo-leptos-webdriver-test.toml new file mode 100644 index 000000000..27364431a --- /dev/null +++ b/examples/cargo-make/cargo-leptos-webdriver-test.toml @@ -0,0 +1,7 @@ +extend = [ + { path = "./cargo-leptos.toml" }, + { path = "../cargo-make/webdriver.toml" }, +] + +[tasks.integration-test] +dependencies = ["install-cargo-leptos", "start-webdriver", "cargo-leptos-e2e"] diff --git a/examples/cargo-make/cargo-leptos.toml b/examples/cargo-make/cargo-leptos.toml index f44598285..5bbd037a0 100644 --- a/examples/cargo-make/cargo-leptos.toml +++ b/examples/cargo-make/cargo-leptos.toml @@ -1,6 +1,12 @@ +extend = { path = "../cargo-make/client-process.toml" } + [tasks.install-cargo-leptos] install_crate = { crate_name = "cargo-leptos", binary = "cargo-leptos", test_arg = "--help" } +[tasks.cargo-leptos-e2e] +command = "cargo" +args = ["leptos", "end-to-end"] + [tasks.build] clear = true command = "cargo" @@ -25,31 +31,3 @@ install_crate = "cargo-all-features" [tasks.start-client] command = "cargo" args = ["leptos", "watch"] - -[tasks.stop-client] -condition = { env_set = ["APP_PROCESS_NAME"] } -script = ''' - if [ ! -z $(pidof ${APP_PROCESS_NAME}) ]; then - pkill -f todo_app_sqlite - fi - - if [ ! -z $(pidof ${APP_PROCESS_NAME}) ]; then - pkill -f cargo-leptos - fi -''' - -[tasks.client-status] -condition = { env_set = ["APP_PROCESS_NAME"] } -script = ''' - if [ -z $(pidof ${APP_PROCESS_NAME}) ]; then - echo " ${APP_PROCESS_NAME} is not running" - else - echo " ${APP_PROCESS_NAME} is up" - fi - - if [ -z $(pidof cargo-leptos) ]; then - echo " cargo-leptos is not running" - else - echo " cargo-leptos is up" - fi -''' diff --git a/examples/cargo-make/client-process.toml b/examples/cargo-make/client-process.toml new file mode 100644 index 000000000..33193f503 --- /dev/null +++ b/examples/cargo-make/client-process.toml @@ -0,0 +1,35 @@ +[tasks.start-client] + +[tasks.stop-client] +condition = { env_set = ["CLIENT_PROCESS_NAME"] } +script = ''' + if [ ! -z $(pidof ${CLIENT_PROCESS_NAME}) ]; then + pkill -ef ${CLIENT_PROCESS_NAME} + fi +''' + +[tasks.client-status] +condition = { env_set = ["CLIENT_PROCESS_NAME"] } +script = ''' + if [ -z $(pidof ${CLIENT_PROCESS_NAME}) ]; then + echo " ${CLIENT_PROCESS_NAME} is not running" + else + echo " ${CLIENT_PROCESS_NAME} is up" + fi +''' + +[tasks.maybe-start-client] +condition = { env_set = ["CLIENT_PROCESS_NAME"] } +script = ''' + if [ -z $(pidof ${CLIENT_PROCESS_NAME}) ]; then + echo " Starting ${CLIENT_PROCESS_NAME}" + cargo make start-client ${@} & + else + echo " ${CLIENT_PROCESS_NAME} is already started" + fi +''' + +# ALIASES + +[tasks.dev] +alias = "maybe-start-client" diff --git a/examples/cargo-make/playwright-trunk-test.toml b/examples/cargo-make/playwright-trunk-test.toml index f37698d4f..36c3dfa7d 100644 --- a/examples/cargo-make/playwright-trunk-test.toml +++ b/examples/cargo-make/playwright-trunk-test.toml @@ -5,10 +5,10 @@ extend = [ [tasks.integration-test] dependencies = [ - "maybe-start-trunk", + "maybe-start-client", "wait-one", "test-playwright", - "stop-trunk", + "stop-client", ] [tasks.wait-one] diff --git a/examples/cargo-make/trunk_server.toml b/examples/cargo-make/trunk_server.toml index 85f975e59..a0fbd42dd 100644 --- a/examples/cargo-make/trunk_server.toml +++ b/examples/cargo-make/trunk_server.toml @@ -1,36 +1,12 @@ +extend = { path = "../cargo-make/client-process.toml" } + +[env] +CLIENT_PROCESS_NAME = "trunk" + [tasks.build] command = "trunk" args = ["build"] -[tasks.start-trunk] +[tasks.start-client] command = "trunk" args = ["serve", "${@}"] - -[tasks.stop-trunk] -script = ''' - pkill -ef "trunk" -''' - -[tasks.trunk-status] -script = ''' - if [ -z $(pidof trunk) ]; then - echo trunk is not running - else - echo trunk is up - fi -''' - -[tasks.maybe-start-trunk] -script = ''' - if [ -z $(pidof trunk) ]; then - echo Starting trunk... - cargo make start-trunk ${@} & - else - echo Trunk already started - fi -''' - -# ALIASES - -[tasks.dev] -dependencies = ["start-trunk"] diff --git a/examples/suspense_tests/Makefile.toml b/examples/suspense_tests/Makefile.toml index a7fb6eaf2..73158a048 100644 --- a/examples/suspense_tests/Makefile.toml +++ b/examples/suspense_tests/Makefile.toml @@ -1,22 +1,10 @@ extend = [ { path = "../cargo-make/main.toml" }, - { path = "../cargo-make/webdriver.toml" }, - { path = "../cargo-make/cargo-leptos.toml" }, + { path = "../cargo-make/cargo-leptos-webdriver-test.toml" }, ] [env] -APP_PROCESS_NAME = "suspense_tests" - -[tasks.integration-test] -dependencies = [ - "install-cargo-leptos", - "start-webdriver", - "test-e2e-with-auto-start", -] - -[tasks.test-e2e-with-auto-start] -command = "cargo" -args = ["leptos", "end-to-end"] +CLIENT_PROCESS_NAME = "suspense_tests" [tasks.test-ui] cwd = "./e2e" diff --git a/examples/tailwind/Makefile.toml b/examples/tailwind/Makefile.toml index 23e176d74..04177c965 100644 --- a/examples/tailwind/Makefile.toml +++ b/examples/tailwind/Makefile.toml @@ -1,4 +1,8 @@ extend = [ { path = "../cargo-make/main.toml" }, + { path = "../cargo-make/playwright.toml" }, { path = "../cargo-make/cargo-leptos-test.toml" }, ] + +[env] +CLIENT_PROCESS_NAME = "tailwind" diff --git a/examples/todo_app_sqlite/Makefile.toml b/examples/todo_app_sqlite/Makefile.toml index eb7ccc03d..4caca105f 100644 --- a/examples/todo_app_sqlite/Makefile.toml +++ b/examples/todo_app_sqlite/Makefile.toml @@ -1,22 +1,10 @@ extend = [ { path = "../cargo-make/main.toml" }, - { path = "../cargo-make/webdriver.toml" }, - { path = "../cargo-make/cargo-leptos.toml" }, + { path = "../cargo-make/cargo-leptos-webdriver-test.toml" }, ] [env] -APP_PROCESS_NAME = "todo_app_sqlite" - -[tasks.integration-test] -dependencies = [ - "install-cargo-leptos", - "start-webdriver", - "test-e2e-with-auto-start", -] - -[tasks.test-e2e-with-auto-start] -command = "cargo" -args = ["leptos", "end-to-end"] +CLIENT_PROCESS_NAME = "todo_app_sqlite" [tasks.test-ui] cwd = "./e2e" diff --git a/examples/todo_app_sqlite_axum/Makefile.toml b/examples/todo_app_sqlite_axum/Makefile.toml index 7795fa3ed..d5fd86f31 100644 --- a/examples/todo_app_sqlite_axum/Makefile.toml +++ b/examples/todo_app_sqlite_axum/Makefile.toml @@ -1,22 +1,10 @@ extend = [ { path = "../cargo-make/main.toml" }, - { path = "../cargo-make/webdriver.toml" }, - { path = "../cargo-make/cargo-leptos.toml" }, + { path = "../cargo-make/cargo-leptos-webdriver-test.toml" }, ] [env] -APP_PROCESS_NAME = "todo_app_sqlite_axum" - -[tasks.integration-test] -dependencies = [ - "install-cargo-leptos", - "start-webdriver", - "test-e2e-with-auto-start", -] - -[tasks.test-e2e-with-auto-start] -command = "cargo" -args = ["leptos", "end-to-end"] +CLIENT_PROCESS_NAME = "todo_app_sqlite_axum" [tasks.test-ui] cwd = "./e2e"