Skip to content

Commit

Permalink
refactor(examples): extract client process tasks (#1665) (#1666)
Browse files Browse the repository at this point in the history
* doc(test-report): report trunk and node

* refactor(examples): extract client process tasks

* chore(exaples): force ci
  • Loading branch information
agilarity authored Sep 8, 2023
1 parent 03cabf6 commit 905d46a
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 137 deletions.
59 changes: 29 additions & 30 deletions examples/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/*' |
Expand All @@ -80,37 +78,43 @@ 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
*"cucumber"*)
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/playwright-trunk-test.toml"*)
crate_symbols=$crate_symbols"P"
crate_symbols=$crate_symbols"T"
;;
*"cargo-make/cargo-leptos-test"*)
*"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"
Expand All @@ -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"
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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).
4 changes: 0 additions & 4 deletions examples/cargo-make/cargo-leptos-test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 7 additions & 0 deletions examples/cargo-make/cargo-leptos-webdriver-test.toml
Original file line number Diff line number Diff line change
@@ -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"]
34 changes: 6 additions & 28 deletions examples/cargo-make/cargo-leptos.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
'''
35 changes: 35 additions & 0 deletions examples/cargo-make/client-process.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions examples/cargo-make/playwright-trunk-test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
36 changes: 6 additions & 30 deletions examples/cargo-make/trunk_server.toml
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 2 additions & 14 deletions examples/suspense_tests/Makefile.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 4 additions & 0 deletions examples/tailwind/Makefile.toml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 2 additions & 14 deletions examples/todo_app_sqlite/Makefile.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 2 additions & 14 deletions examples/todo_app_sqlite_axum/Makefile.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 905d46a

Please sign in to comment.