From e1d94b36eaca802800567f55547e15a7147c99d0 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 5 Feb 2024 15:58:08 +0530 Subject: [PATCH 01/12] chore: added tests for SSR --- .github/scripts/run-ssr-test.sh | 46 ++++++++ .github/scripts/test-ssr.py | 29 +++++ .github/workflows/test.yml | 5 + Cargo.lock | 4 +- ssr-test/FASTN.ftd | 5 + ssr-test/assets/ipsum-logo-dark.svg | 162 ++++++++++++++++++++++++++++ ssr-test/assets/ipsum-logo.svg | 152 ++++++++++++++++++++++++++ ssr-test/index.ftd | 15 +++ 8 files changed, 416 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/run-ssr-test.sh create mode 100644 .github/scripts/test-ssr.py create mode 100644 ssr-test/FASTN.ftd create mode 100644 ssr-test/assets/ipsum-logo-dark.svg create mode 100644 ssr-test/assets/ipsum-logo.svg create mode 100644 ssr-test/index.ftd diff --git a/.github/scripts/run-ssr-test.sh b/.github/scripts/run-ssr-test.sh new file mode 100755 index 0000000000..a318e2849b --- /dev/null +++ b/.github/scripts/run-ssr-test.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +FASTN_ROOT=$(pwd) +FASTN_SERVE_PID="" + +terminate_fastn_serve() { + echo "Terminating fastn serve process ..." + if [ -n "$FASTN_SERVE_PID" ]; then + kill -9 "$FASTN_SERVE_PID" + fi +} + +handle_error() { + local ret=$? + echo "Error occurred, terminating script..." + terminate_fastn_serve + exit $ret +} + +trap 'handle_error' ERR + +echo "Installing required python dependencies ..." +pip install pyquery requests + +cd "$FASTN_ROOT/ssr-test" + +echo "Updating fastn packages ..." +fastn update + +echo "Starting fastn server in the background..." +fastn serve --offline & +FASTN_SERVE_PID=$! + +# Wait for the server to start +sleep 5 + +echo "Running tests ..." +# Run the Python script and catch assertion errors +if python "${FASTN_ROOT}/.github/scripts/test-ssr.py" "http://127.0.0.1:8000"; then + echo "SSR test passed successfully" +else + echo "SSR test failed with assertion error" + exit 1 +fi + +terminate_fastn_serve diff --git a/.github/scripts/test-ssr.py b/.github/scripts/test-ssr.py new file mode 100644 index 0000000000..20c379c4b5 --- /dev/null +++ b/.github/scripts/test-ssr.py @@ -0,0 +1,29 @@ +from pyquery import PyQuery as pq +import requests +import sys + +def test_ssr(url): + user_agents = [ + "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123 Safari/537.36" + ] + + for user_agent in user_agents: + headers = {'User-Agent': user_agent} + response = requests.get(url, headers=headers) + doc = pq(response.text) + + body_tag = doc('body') + + if "Googlebot" in user_agent: + assert len(body_tag.children()) > 0 + else: + assert not body_tag.children() + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python test-ssr.py ") + sys.exit(1) + + url = sys.argv[1] + test_ssr(url.strip()) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6695815ae4..1534b2c5a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -97,6 +97,11 @@ jobs: continue-on-error: true run: | bash .github/scripts/run-integration-tests.sh + - name: Run SSR test + id: ssr-test + continue-on-error: false + run: | + bash .github/scripts/run-ssr-test.sh - name: Check if JS code is properly formatted # curl -fsSL https://dprint.dev/install.sh | sh # /Users/amitu/.dprint/bin/dprint fmt --config .github/dprint-ci.json diff --git a/Cargo.lock b/Cargo.lock index a8a50d0861..1bece5bb08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5519,9 +5519,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.5.36" +version = "0.5.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "818ce546a11a9986bc24f93d0cdf38a8a1a400f1473ea8c82e59f6e0ffab9249" +checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5" dependencies = [ "memchr", ] diff --git a/ssr-test/FASTN.ftd b/ssr-test/FASTN.ftd new file mode 100644 index 0000000000..ce084c976d --- /dev/null +++ b/ssr-test/FASTN.ftd @@ -0,0 +1,5 @@ +-- import: fastn + +-- fastn.package: fastn-community.github.io/ssr-test + +-- fastn.dependency: fastn-community.github.io/business-card diff --git a/ssr-test/assets/ipsum-logo-dark.svg b/ssr-test/assets/ipsum-logo-dark.svg new file mode 100644 index 0000000000..0dfb673b7c --- /dev/null +++ b/ssr-test/assets/ipsum-logo-dark.svg @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ssr-test/assets/ipsum-logo.svg b/ssr-test/assets/ipsum-logo.svg new file mode 100644 index 0000000000..e051e3fa36 --- /dev/null +++ b/ssr-test/assets/ipsum-logo.svg @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ssr-test/index.ftd b/ssr-test/index.ftd new file mode 100644 index 0000000000..930a8cadeb --- /dev/null +++ b/ssr-test/index.ftd @@ -0,0 +1,15 @@ +-- import: fastn-community.github.io/business-card as b-card +-- import: fastn-community.github.io/ssr-test/assets + +-- ftd.text: Hello SSR! + +-- b-card.card: John Doe +title: Software Developer +company-name: John Doe Pvt. Ltd. +logo: $assets.files.assets.ipsum-logo.svg +contact-1: +91 12345 99999 +contact-2: +91 12345 88888 +email: john@johndoe.com +website: www.johndoe.com +address: 123, Block No. A-123, Times Square, Bangalore - 123456 +company-slogan: If you can type you can code From ed6995b4b976063da4826afd3a4dc1842def9e6d Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 5 Feb 2024 16:05:05 +0530 Subject: [PATCH 02/12] minor changes --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1534b2c5a2..9a15ac1b77 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -99,7 +99,7 @@ jobs: bash .github/scripts/run-integration-tests.sh - name: Run SSR test id: ssr-test - continue-on-error: false + continue-on-error: true run: | bash .github/scripts/run-ssr-test.sh - name: Check if JS code is properly formatted @@ -127,3 +127,6 @@ jobs: - name: Check if integration test passed if: steps.integration-test.outcome != 'success' run: exit 1 + - name: Check if SSR test passed + if: steps.ssr-test.outcome != 'success' + run: exit 1 From ccac4de0c543fd64335ef477179a72782f779cbe Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 5 Feb 2024 16:19:51 +0530 Subject: [PATCH 03/12] minor changes --- .github/scripts/run-ssr-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/run-ssr-test.sh b/.github/scripts/run-ssr-test.sh index a318e2849b..6aa686167d 100755 --- a/.github/scripts/run-ssr-test.sh +++ b/.github/scripts/run-ssr-test.sh @@ -28,7 +28,7 @@ echo "Updating fastn packages ..." fastn update echo "Starting fastn server in the background..." -fastn serve --offline & +fastn --test serve --offline & FASTN_SERVE_PID=$! # Wait for the server to start From 46a692832067446211cdee43b3f64319d8dd04a5 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Mon, 5 Feb 2024 16:40:37 +0530 Subject: [PATCH 04/12] install fastn --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a15ac1b77..1fc7440ee6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -101,6 +101,7 @@ jobs: id: ssr-test continue-on-error: true run: | + cargo install --path=fastn bash .github/scripts/run-ssr-test.sh - name: Check if JS code is properly formatted # curl -fsSL https://dprint.dev/install.sh | sh From 01beffb5756651a8092560972c861f3725da5861 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Tue, 6 Feb 2024 13:05:02 +0530 Subject: [PATCH 05/12] use fbt to test bot ssr --- .github/scripts/run-ssr-test.sh | 46 - .github/scripts/test-ssr.py | 29 - .github/workflows/test.yml | 9 - fastn-core/tests/01-help/cmd.p1 | 2 +- fastn-core/tests/02-hello/cmd.p1 | 2 +- fastn-core/tests/03-nested-document/cmd.p1 | 2 +- fastn-core/tests/04-import-code-block/cmd.p1 | 2 +- fastn-core/tests/05-hello-font/cmd.p1 | 2 +- fastn-core/tests/08-static-assets/cmd.p1 | 2 +- fastn-core/tests/09-markdown-pages/cmd.p1 | 2 +- fastn-core/tests/10-readme-index/cmd.p1 | 2 +- fastn-core/tests/11-readme-with-index/cmd.p1 | 2 +- fastn-core/tests/16-include-processor/cmd.p1 | 2 +- fastn-core/tests/17-sitemap/cmd.p1 | 2 +- fastn-core/tests/18-fmt/cmd.p1 | 2 +- fastn-core/tests/19-bot-ssr/cmd.p1 | 13 + .../tests/19-bot-ssr/input}/FASTN.ftd | 0 .../input}/assets/ipsum-logo-dark.svg | 0 .../19-bot-ssr/input}/assets/ipsum-logo.svg | 0 .../tests/19-bot-ssr/input}/index.ftd | 0 .../19-bot-ssr/output/index-with-ssr.html | 999 ++++++++++++++++++ .../19-bot-ssr/output/index-without-ssr.html | 927 ++++++++++++++++ fastn-core/tests/19-bot-ssr/run-test.sh | 31 + fastn-core/tests/fbt.p1 | 2 +- 24 files changed, 1983 insertions(+), 97 deletions(-) delete mode 100755 .github/scripts/run-ssr-test.sh delete mode 100644 .github/scripts/test-ssr.py create mode 100644 fastn-core/tests/19-bot-ssr/cmd.p1 rename {ssr-test => fastn-core/tests/19-bot-ssr/input}/FASTN.ftd (100%) rename {ssr-test => fastn-core/tests/19-bot-ssr/input}/assets/ipsum-logo-dark.svg (100%) rename {ssr-test => fastn-core/tests/19-bot-ssr/input}/assets/ipsum-logo.svg (100%) rename {ssr-test => fastn-core/tests/19-bot-ssr/input}/index.ftd (100%) create mode 100644 fastn-core/tests/19-bot-ssr/output/index-with-ssr.html create mode 100644 fastn-core/tests/19-bot-ssr/output/index-without-ssr.html create mode 100755 fastn-core/tests/19-bot-ssr/run-test.sh diff --git a/.github/scripts/run-ssr-test.sh b/.github/scripts/run-ssr-test.sh deleted file mode 100755 index 6aa686167d..0000000000 --- a/.github/scripts/run-ssr-test.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -FASTN_ROOT=$(pwd) -FASTN_SERVE_PID="" - -terminate_fastn_serve() { - echo "Terminating fastn serve process ..." - if [ -n "$FASTN_SERVE_PID" ]; then - kill -9 "$FASTN_SERVE_PID" - fi -} - -handle_error() { - local ret=$? - echo "Error occurred, terminating script..." - terminate_fastn_serve - exit $ret -} - -trap 'handle_error' ERR - -echo "Installing required python dependencies ..." -pip install pyquery requests - -cd "$FASTN_ROOT/ssr-test" - -echo "Updating fastn packages ..." -fastn update - -echo "Starting fastn server in the background..." -fastn --test serve --offline & -FASTN_SERVE_PID=$! - -# Wait for the server to start -sleep 5 - -echo "Running tests ..." -# Run the Python script and catch assertion errors -if python "${FASTN_ROOT}/.github/scripts/test-ssr.py" "http://127.0.0.1:8000"; then - echo "SSR test passed successfully" -else - echo "SSR test failed with assertion error" - exit 1 -fi - -terminate_fastn_serve diff --git a/.github/scripts/test-ssr.py b/.github/scripts/test-ssr.py deleted file mode 100644 index 20c379c4b5..0000000000 --- a/.github/scripts/test-ssr.py +++ /dev/null @@ -1,29 +0,0 @@ -from pyquery import PyQuery as pq -import requests -import sys - -def test_ssr(url): - user_agents = [ - "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123 Safari/537.36" - ] - - for user_agent in user_agents: - headers = {'User-Agent': user_agent} - response = requests.get(url, headers=headers) - doc = pq(response.text) - - body_tag = doc('body') - - if "Googlebot" in user_agent: - assert len(body_tag.children()) > 0 - else: - assert not body_tag.children() - -if __name__ == "__main__": - if len(sys.argv) < 2: - print("Usage: python test-ssr.py ") - sys.exit(1) - - url = sys.argv[1] - test_ssr(url.strip()) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1fc7440ee6..6695815ae4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -97,12 +97,6 @@ jobs: continue-on-error: true run: | bash .github/scripts/run-integration-tests.sh - - name: Run SSR test - id: ssr-test - continue-on-error: true - run: | - cargo install --path=fastn - bash .github/scripts/run-ssr-test.sh - name: Check if JS code is properly formatted # curl -fsSL https://dprint.dev/install.sh | sh # /Users/amitu/.dprint/bin/dprint fmt --config .github/dprint-ci.json @@ -128,6 +122,3 @@ jobs: - name: Check if integration test passed if: steps.integration-test.outcome != 'success' run: exit 1 - - name: Check if SSR test passed - if: steps.ssr-test.outcome != 'success' - run: exit 1 diff --git a/fastn-core/tests/01-help/cmd.p1 b/fastn-core/tests/01-help/cmd.p1 index b8b70c7ecf..4c29ed5c25 100644 --- a/fastn-core/tests/01-help/cmd.p1 +++ b/fastn-core/tests/01-help/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test --help +cmd: $FBT_CWD/../target/release/fastn --test --help Will have to be updated every time version changes. diff --git a/fastn-core/tests/02-hello/cmd.p1 b/fastn-core/tests/02-hello/cmd.p1 index 6c894875a1..33f3a6c867 100644 --- a/fastn-core/tests/02-hello/cmd.p1 +++ b/fastn-core/tests/02-hello/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 --ignore-failed +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 --ignore-failed output: amitu/.build -- stdout: diff --git a/fastn-core/tests/03-nested-document/cmd.p1 b/fastn-core/tests/03-nested-document/cmd.p1 index c25a6077dc..c04917ad4f 100644 --- a/fastn-core/tests/03-nested-document/cmd.p1 +++ b/fastn-core/tests/03-nested-document/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 output: amitu/.build diff --git a/fastn-core/tests/04-import-code-block/cmd.p1 b/fastn-core/tests/04-import-code-block/cmd.p1 index 1dbd20aee8..42924493b7 100644 --- a/fastn-core/tests/04-import-code-block/cmd.p1 +++ b/fastn-core/tests/04-import-code-block/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 output: amitu/.build diff --git a/fastn-core/tests/05-hello-font/cmd.p1 b/fastn-core/tests/05-hello-font/cmd.p1 index 93306b148c..e7b4f6db3a 100644 --- a/fastn-core/tests/05-hello-font/cmd.p1 +++ b/fastn-core/tests/05-hello-font/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 output: amitu/.build -- stdout: diff --git a/fastn-core/tests/08-static-assets/cmd.p1 b/fastn-core/tests/08-static-assets/cmd.p1 index 89e6bb8027..9f16603b00 100644 --- a/fastn-core/tests/08-static-assets/cmd.p1 +++ b/fastn-core/tests/08-static-assets/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build output: amitu/.build -- stdout: diff --git a/fastn-core/tests/09-markdown-pages/cmd.p1 b/fastn-core/tests/09-markdown-pages/cmd.p1 index 7cfc7cc4ce..330de4ad35 100644 --- a/fastn-core/tests/09-markdown-pages/cmd.p1 +++ b/fastn-core/tests/09-markdown-pages/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build output: amitu/.build -- stdout: diff --git a/fastn-core/tests/10-readme-index/cmd.p1 b/fastn-core/tests/10-readme-index/cmd.p1 index 914620bda8..48083adcd4 100644 --- a/fastn-core/tests/10-readme-index/cmd.p1 +++ b/fastn-core/tests/10-readme-index/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build output: amitu/.build skip: temporarily removed markdown support diff --git a/fastn-core/tests/11-readme-with-index/cmd.p1 b/fastn-core/tests/11-readme-with-index/cmd.p1 index 0ce58b4a37..3f105241fb 100644 --- a/fastn-core/tests/11-readme-with-index/cmd.p1 +++ b/fastn-core/tests/11-readme-with-index/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 output: amitu/.build -- stdout: diff --git a/fastn-core/tests/16-include-processor/cmd.p1 b/fastn-core/tests/16-include-processor/cmd.p1 index 83f2d0459e..a257cc015b 100644 --- a/fastn-core/tests/16-include-processor/cmd.p1 +++ b/fastn-core/tests/16-include-processor/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: $FBT_CWD/../target/release/fastn --test build --edition 2022 output: .build -- stdout: diff --git a/fastn-core/tests/17-sitemap/cmd.p1 b/fastn-core/tests/17-sitemap/cmd.p1 index 9d55613d01..c198a1173c 100644 --- a/fastn-core/tests/17-sitemap/cmd.p1 +++ b/fastn-core/tests/17-sitemap/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test build +cmd: $FBT_CWD/../target/release/fastn --test build output: .build -- stdout: diff --git a/fastn-core/tests/18-fmt/cmd.p1 b/fastn-core/tests/18-fmt/cmd.p1 index 98654015a2..c14bdc4d71 100644 --- a/fastn-core/tests/18-fmt/cmd.p1 +++ b/fastn-core/tests/18-fmt/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test fmt +cmd: $FBT_CWD/../target/release/fastn --test fmt output: . -- stdout: diff --git a/fastn-core/tests/19-bot-ssr/cmd.p1 b/fastn-core/tests/19-bot-ssr/cmd.p1 new file mode 100644 index 0000000000..57004ae924 --- /dev/null +++ b/fastn-core/tests/19-bot-ssr/cmd.p1 @@ -0,0 +1,13 @@ +-- fbt: +cmd: $FBT_CWD/tests/19-bot-ssr/run-test.sh +output: .build + +-- stdout: + +Updated 2 dependencies. +Starting fastn server ... +Updated 2 dependencies. +### Server Started ### +Go to: http://127.0.0.1:8000 +Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) ... +Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123 Safari/537.36 ... diff --git a/ssr-test/FASTN.ftd b/fastn-core/tests/19-bot-ssr/input/FASTN.ftd similarity index 100% rename from ssr-test/FASTN.ftd rename to fastn-core/tests/19-bot-ssr/input/FASTN.ftd diff --git a/ssr-test/assets/ipsum-logo-dark.svg b/fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo-dark.svg similarity index 100% rename from ssr-test/assets/ipsum-logo-dark.svg rename to fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo-dark.svg diff --git a/ssr-test/assets/ipsum-logo.svg b/fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo.svg similarity index 100% rename from ssr-test/assets/ipsum-logo.svg rename to fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo.svg diff --git a/ssr-test/index.ftd b/fastn-core/tests/19-bot-ssr/input/index.ftd similarity index 100% rename from ssr-test/index.ftd rename to fastn-core/tests/19-bot-ssr/input/index.ftd diff --git a/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html b/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html new file mode 100644 index 0000000000..3092f85199 --- /dev/null +++ b/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html @@ -0,0 +1,999 @@ + + + + + + + + + + + + + + + + + + + + + + +
Hello SSR!
John Doe
Software Developer
+91 12345 99999
+91 12345 88888
John Doe Pvt. Ltd.
123, Block No. A-123, Times Square, Bangalore - 123456
+ + diff --git a/fastn-core/tests/19-bot-ssr/output/index-without-ssr.html b/fastn-core/tests/19-bot-ssr/output/index-without-ssr.html new file mode 100644 index 0000000000..7b8906ce6e --- /dev/null +++ b/fastn-core/tests/19-bot-ssr/output/index-without-ssr.html @@ -0,0 +1,927 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/fastn-core/tests/19-bot-ssr/run-test.sh b/fastn-core/tests/19-bot-ssr/run-test.sh new file mode 100755 index 0000000000..c7d1ae5330 --- /dev/null +++ b/fastn-core/tests/19-bot-ssr/run-test.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +FASTN="$FBT_CWD/../target/release/fastn" +SITE_URL="http://127.0.0.1:8000" +BOT_USER_AGENT="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" +NORMAL_USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123 Safari/537.36" + +"$FASTN" --test update + +echo "Starting fastn server ..." +"$FASTN" --test serve --offline & +FASTN_SERVE_PID=$! + +sleep 5 + +build_dir=".build" +if [ ! -d "$build_dir" ]; then + mkdir "$build_dir" +fi + +echo "Curling $SITE_URL with User Agent $BOT_USER_AGENT ..." +curl -A "$BOT_USER_AGENT" -s "$SITE_URL" -o "$build_dir/index-with-ssr.html" + +sleep 5 + +echo "Curling $SITE_URL with User Agent $NORMAL_USER_AGENT ..." +curl -A "$NORMAL_USER_AGENT" -s "$SITE_URL" -o "$build_dir/index-without-ssr.html" + +sleep 5 + +kill -9 "$FASTN_SERVE_PID" diff --git a/fastn-core/tests/fbt.p1 b/fastn-core/tests/fbt.p1 index d9c74ffd2f..ddd68e5598 100644 --- a/fastn-core/tests/fbt.p1 +++ b/fastn-core/tests/fbt.p1 @@ -1,2 +1,2 @@ -- fbt: -build: cd .. && cargo install --path fastn --profile dev --features auth +build: cd .. && cargo install --path fastn --profile release --features auth From a362d3b852fb903bc14b68d8f4528ebed6e05988 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Tue, 6 Feb 2024 16:04:44 +0530 Subject: [PATCH 06/12] minor changes --- fastn-core/tests/19-bot-ssr/cmd.p1 | 4 +- fastn-core/tests/19-bot-ssr/input/FASTN.ftd | 2 - fastn-core/tests/19-bot-ssr/input/index.ftd | 20 +- .../19-bot-ssr/output/index-with-ssr.html | 610 +----------------- .../19-bot-ssr/output/index-without-ssr.html | 536 +-------------- 5 files changed, 34 insertions(+), 1138 deletions(-) diff --git a/fastn-core/tests/19-bot-ssr/cmd.p1 b/fastn-core/tests/19-bot-ssr/cmd.p1 index 57004ae924..b15161ca02 100644 --- a/fastn-core/tests/19-bot-ssr/cmd.p1 +++ b/fastn-core/tests/19-bot-ssr/cmd.p1 @@ -4,9 +4,9 @@ output: .build -- stdout: -Updated 2 dependencies. +Updated package dependency Starting fastn server ... -Updated 2 dependencies. +Updated package dependency ### Server Started ### Go to: http://127.0.0.1:8000 Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) ... diff --git a/fastn-core/tests/19-bot-ssr/input/FASTN.ftd b/fastn-core/tests/19-bot-ssr/input/FASTN.ftd index ce084c976d..6c57c15503 100644 --- a/fastn-core/tests/19-bot-ssr/input/FASTN.ftd +++ b/fastn-core/tests/19-bot-ssr/input/FASTN.ftd @@ -1,5 +1,3 @@ -- import: fastn -- fastn.package: fastn-community.github.io/ssr-test - --- fastn.dependency: fastn-community.github.io/business-card diff --git a/fastn-core/tests/19-bot-ssr/input/index.ftd b/fastn-core/tests/19-bot-ssr/input/index.ftd index 930a8cadeb..15d0a99c06 100644 --- a/fastn-core/tests/19-bot-ssr/input/index.ftd +++ b/fastn-core/tests/19-bot-ssr/input/index.ftd @@ -1,15 +1,13 @@ --- import: fastn-community.github.io/business-card as b-card -- import: fastn-community.github.io/ssr-test/assets +-- ftd.column: +width: fill-container +height: fill-container +align-content: center +spacing.fixed.rem: 2 + +-- ftd.image: $assets.files.assets.ipsum-logo.svg + -- ftd.text: Hello SSR! --- b-card.card: John Doe -title: Software Developer -company-name: John Doe Pvt. Ltd. -logo: $assets.files.assets.ipsum-logo.svg -contact-1: +91 12345 99999 -contact-2: +91 12345 88888 -email: john@johndoe.com -website: www.johndoe.com -address: 123, Block No. A-123, Times Square, Bangalore - 123456 -company-slogan: If you can type you can code +-- end: ftd.column diff --git a/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html b/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html index 3092f85199..8ab805e4cd 100644 --- a/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html +++ b/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html @@ -16,7 +16,7 @@ - + @@ -332,78 +332,14 @@ -
Hello SSR!
John Doe
Software Developer
+91 12345 99999
+91 12345 88888
John Doe Pvt. Ltd.
123, Block No. A-123, Times Square, Bangalore - 123456
- + @@ -339,541 +339,25 @@ let __fastn_super_package_name__ = __fastn_package_name__; __fastn_package_name__ = "fastn_community_github_io_ssr_test"; try { - let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Text); - parenti0.setProperty(fastn_dom.PropertyKind.StringValue, "Hello SSR!", inherited); - let parenti1 = fastn_community_github_io_business_card__card(parent, inherited, { - name: "John Doe", - title: "Software Developer", - company_name: "John Doe Pvt. Ltd.", - logo: global.fastn_community_github_io_ssr_test_assets__files.get("assets").get("ipsum_logo").get("svg"), - contact_1: "+91 12345 99999", - contact_2: "+91 12345 88888", - email: "john@johndoe.com", - website: "www.johndoe.com", - address: "123, Block No. A-123, Times Square, Bangalore - 123456", - company_slogan: "If you can type you can code" - }); - } finally { - __fastn_package_name__ = __fastn_super_package_name__; - } -} -global["main"] = main; -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card_assets__files.assets.fastn_badge_white.svg", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "-/fastn-community.github.io/business-card/assets/fastn-badge-white.svg"); - record.set("dark", "-/fastn-community.github.io/business-card/assets/fastn-badge-white-dark.svg"); - return record; -}()); -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card_assets__files.assets.download_hover.svg", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "-/fastn-community.github.io/business-card/assets/download-hover.svg"); - record.set("dark", "-/fastn-community.github.io/business-card/assets/download-hover-dark.svg"); - return record; -}()); -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card_assets__files.assets.download.svg", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "-/fastn-community.github.io/business-card/assets/download.svg"); - record.set("dark", "-/fastn-community.github.io/business-card/assets/download-dark.svg"); - return record; -}()); -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card_assets__files.assets.flip_icon.svg", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "-/fastn-community.github.io/business-card/assets/flip-icon.svg"); - record.set("dark", "-/fastn-community.github.io/business-card/assets/flip-icon-dark.svg"); - return record; -}()); -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card_assets__files.assets.flip_icon_hover.svg", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "-/fastn-community.github.io/business-card/assets/flip-icon-hover.svg"); - record.set("dark", "-/fastn-community.github.io/business-card/assets/flip-icon-hover-dark.svg"); - return record; -}()); -fastn_utils.createNestedObject(global, "fastn_stack_github_io_fastn_js_assets__files.download.js", "-/fastn-stack.github.io/fastn-js/download.js"); -let fastn_stack_github_io_fastn_js_utils__download_as_image = function (args) -{ - let __fastn_super_package_name__ = __fastn_package_name__; - __fastn_package_name__ = "fastn_community_github_io_ssr_test"; - try { - let __args__ = fastn_utils.getArgs({ - }, args); - return (download_as_image(__args__.element_id, __args__.filename)); - } catch (e) { - if (!ssr) { - throw e; - } - } finally { - __fastn_package_name__ = __fastn_super_package_name__; - } -} -global["fastn_stack_github_io_fastn_js_utils__download_as_image"] = fastn_stack_github_io_fastn_js_utils__download_as_image; -let fastn_community_github_io_business_card_lib__display_card = function (parent, inherited, args) -{ - let __fastn_super_package_name__ = __fastn_package_name__; - __fastn_package_name__ = "fastn_community_github_io_ssr_test"; - try { - let __args__ = { - front: fastn.mutableList([]), - back: fastn.mutableList([]), - landscape: true, - card_id: "some-card-id-for-download-purpose", - open: fastn.wrapMutable(false), - mouse_in: fastn.wrapMutable(false), - on_hover: fastn.wrapMutable(false), - mouse_over: fastn.wrapMutable(false), - }; - inherited = fastn_utils.getInheritedValues(__args__, inherited, args); - __args__ = fastn_utils.getArgs(__args__, args); - let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Row); - parenti0.setProperty(fastn_dom.PropertyKind.Width, fastn.formula([ftd.device], function () { - if (function () { - return (fastn_utils.getStaticValue(ftd.device) == "mobile"); - }()) { - return fastn_dom.Resizing.FillContainer; - } - } - ), inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.Fixed(fastn_dom.Length.Px(24)), inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Id, __args__.card_id, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.open - ], function () { - return (!fastn_utils.getStaticValue(__args__.open)); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn.formula([__args__.landscape], function () { - if (function () { - return fastn_utils.getStaticValue(__args__.landscape); - }()) { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(700)); - } else { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(350)); - } - } - ), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn.formula([__args__.landscape], function () { - if (function () { - return fastn_utils.getStaticValue(__args__.landscape); - }()) { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(350)); - } else { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(500)); - } - } - ), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_utils.getStaticValue(fastn_utils.getListItem(__args__.front.get(0))) (root, inherited); - } - ]), inherited); - return rooti0; - }); - }, - function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.open - ], function () { - return fastn_utils.getStaticValue(__args__.open); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn.formula([__args__.landscape], function () { - if (function () { - return fastn_utils.getStaticValue(__args__.landscape); - }()) { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(700)); - } else { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(350)); - } - } - ), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn.formula([__args__.landscape], function () { - if (function () { - return fastn_utils.getStaticValue(__args__.landscape); - }()) { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(350)); - } else { - return fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(500)); - } - } - ), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_utils.getStaticValue(fastn_utils.getListItem(__args__.back.get(0))) (root, inherited); - } - ]), inherited); - return rooti0; - }); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); - rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, global.fastn_community_github_io_business_card_assets__files.get("assets").get("fastn_badge_white").get("svg"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.AlignSelf, fastn_dom.AlignSelf.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(140)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MarginTop, fastn_dom.Length.Px(8), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Link, "https://fastn.com/", inherited); - rooti0.setProperty(fastn_dom.PropertyKind.OpenInNewTab, true, inherited); - } - ]), inherited); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.Fixed(fastn_dom.Length.Px(12)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); - rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, fastn.formula([global.fastn_community_github_io_business_card_assets__files.get("assets").get("flip_icon_hover").get("svg"), - global.fastn_community_github_io_business_card_assets__files.get("assets").get("flip_icon").get("svg"), - __args__.mouse_in], function () { - if (function () { - return (!fastn_utils.getStaticValue(__args__.mouse_in)); - }()) { - return global.fastn_community_github_io_business_card_assets__files.get("assets").get("flip_icon").get("svg"); - } else { - return global.fastn_community_github_io_business_card_assets__files.get("assets").get("flip_icon_hover").get("svg"); - } - } - ), inherited); - rooti0.addEventHandler(fastn_dom.Event.Click, function () { - ftd.toggle({ - a: __args__.open, - }, rooti0); - }); - rooti0.addEventHandler(fastn_dom.Event.MouseEnter, function () { - ftd.set_bool({ - a: __args__.mouse_in, - v: true, - }, rooti0); - }); - rooti0.addEventHandler(fastn_dom.Event.MouseLeave, function () { - ftd.set_bool({ - a: __args__.mouse_in, - v: false, - }, rooti0); - }); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(24)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(24)), inherited); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); - rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, fastn.formula([global.fastn_community_github_io_business_card_assets__files.get("assets").get("download").get("svg"), - global.fastn_community_github_io_business_card_assets__files.get("assets").get("download_hover").get("svg"), - __args__.mouse_over], function () { - if (function () { - return fastn_utils.getStaticValue(__args__.mouse_over); - }()) { - return global.fastn_community_github_io_business_card_assets__files.get("assets").get("download_hover").get("svg"); - } else { - return global.fastn_community_github_io_business_card_assets__files.get("assets").get("download").get("svg"); - } - } - ), inherited); - rooti0.addEventHandler(fastn_dom.Event.Click, function () { - fastn_stack_github_io_fastn_js_utils__download_as_image({ - element_id: __args__.card_id, - filename: "card.jpg", - }, rooti0); - }); - rooti0.addEventHandler(fastn_dom.Event.MouseEnter, function () { - ftd.set_bool({ - a: __args__.mouse_over, - v: true, - }, rooti0); - }); - rooti0.addEventHandler(fastn_dom.Event.MouseLeave, function () { - ftd.set_bool({ - a: __args__.mouse_over, - v: false, - }, rooti0); - }); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(30)), inherited); - } - ]), inherited); - } - ]), inherited); - return parenti0; - } finally { - __fastn_package_name__ = __fastn_super_package_name__; - } -} -global["fastn_community_github_io_business_card_lib__display_card"] = fastn_community_github_io_business_card_lib__display_card; -fastn_utils.createNestedObject(global, "fastn_community_github_io_business_card__card_background_color", function () { - let record = fastn.recordInstance({ - }); - record.set("light", "#f4edd0"); - record.set("dark", "black"); - return record; -}()); -let fastn_community_github_io_business_card__front = function (parent, inherited, args) -{ - let __fastn_super_package_name__ = __fastn_package_name__; - __fastn_package_name__ = "fastn_community_github_io_ssr_test"; - try { - let __args__ = { - contact_1: null, - contact_2: null, - email: null, - website: null, - address: null, - }; - inherited = fastn_utils.getInheritedValues(__args__, inherited, args); - __args__ = fastn_utils.getArgs(__args__, args); - let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Row); + let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Column); parenti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); parenti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.FillContainer, inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Background, fastn_dom.BackgroundStyle.Solid(global.fastn_community_github_io_business_card__card_background_color), inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.SpaceAround, inherited); + parenti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); + parenti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.Fixed(fastn_dom.Length.Rem(2)), inherited); parenti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.Fixed(fastn_dom.Length.Percent(50)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.SpaceAround, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); - rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, __args__.logo, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MaxWidth, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(250)), inherited); - } - ]), inherited); + let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); + rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, global.fastn_community_github_io_ssr_test_assets__files.get("assets").get("ipsum_logo").get("svg"), inherited); }, function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.Fixed(fastn_dom.Length.Percent(50)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.PaddingHorizontal, fastn_dom.Length.Px(24), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderLeftWidth, fastn_dom.Length.Px(2), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderColor, inherited.get("colors").get("border_strong"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Color, inherited.get("colors").get("text"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.Fixed(fastn_dom.Length.Px(8)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("heading_small"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.name, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Color, inherited.get("colors").get("text_strong"), inherited); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("copy_regular"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.title, inherited); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.MarginTop, fastn_dom.Length.Px(40), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("copy_regular"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.contact_1 - ], function () { - return (fastn_utils.getStaticValue(__args__.contact_1) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.contact_1, inherited); - return rooti0; - }); - }, - function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.contact_2 - ], function () { - return (fastn_utils.getStaticValue(__args__.contact_2) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.contact_2, inherited); - return rooti0; - }); - } - ]), inherited); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.PaddingTop, fastn_dom.Length.Px(8), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MarginTop, fastn_dom.Length.Px(8), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderTopWidth, fastn_dom.Length.Px(1), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderColor, inherited.get("colors").get("border_strong"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("fine_print"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.Fixed(fastn_dom.Length.Px(8)), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("button_medium"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.company_name, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MarginTop, fastn.formula([__args__.contact_1, - __args__.contact_2], function () { - if (function () { - return (fastn_utils.getStaticValue(__args__.contact_1) == null && fastn_utils.getStaticValue(__args__.contact_2) == null); - }()) { - return fastn_dom.Length.Px(50); - } - } - ), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.TextAlign, fastn_dom.TextAlign.Center, inherited); - }, - function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.address - ], function () { - return (fastn_utils.getStaticValue(__args__.address) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.address, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.TextAlign, fastn_dom.TextAlign.Center, inherited); - return rooti0; - }); - }, - function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.email - ], function () { - return (fastn_utils.getStaticValue(__args__.email) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.email, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.TextAlign, fastn_dom.TextAlign.Center, inherited); - return rooti0; - }); - }, - function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.website - ], function () { - return (fastn_utils.getStaticValue(__args__.website) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.website, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.TextAlign, fastn_dom.TextAlign.Center, inherited); - return rooti0; - }); - } - ]), inherited); - } - ]), inherited); - } - ]), inherited); + let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); + rooti0.setProperty(fastn_dom.PropertyKind.StringValue, "Hello SSR!", inherited); } ]), inherited); - return parenti0; } finally { __fastn_package_name__ = __fastn_super_package_name__; } } -global["fastn_community_github_io_business_card__front"] = fastn_community_github_io_business_card__front; -let fastn_community_github_io_business_card__back = function (parent, inherited, args) -{ - let __fastn_super_package_name__ = __fastn_package_name__; - __fastn_package_name__ = "fastn_community_github_io_ssr_test"; - try { - let __args__ = { - company_slogan: null, - }; - inherited = fastn_utils.getInheritedValues(__args__, inherited, args); - __args__ = fastn_utils.getArgs(__args__, args); - let parenti0 = fastn_dom.createKernel(parent, fastn_dom.ElementKind.Row); - parenti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.FillContainer, inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Background, fastn_dom.BackgroundStyle.Solid(global.fastn_community_github_io_business_card__card_background_color), inherited); - parenti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Spacing, fastn_dom.Spacing.SpaceAround, inherited); - parenti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Column); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Height, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Margin, fastn_dom.Length.Px(50), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderLeftWidth, fastn_dom.Length.Px(8), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderRightWidth, fastn_dom.Length.Px(8), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderStyle, fastn_dom.BorderStyle.Double, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.BorderColor, inherited.get("colors").get("border_strong"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.AlignContent, fastn_dom.AlignContent.Center, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Children, fastn.mutableList([function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.logo - ], function () { - return (fastn_utils.getStaticValue(__args__.logo) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Image); - rooti0.setProperty(fastn_dom.PropertyKind.ImageSrc, __args__.logo, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MaxWidth, fastn_dom.Resizing.Fixed(fastn_dom.Length.Px(250)), inherited); - return rooti0; - }); - }, - function (root, inherited) { - fastn_dom.conditionalDom(root, [ - __args__.company_slogan - ], function () { - return (fastn_utils.getStaticValue(__args__.company_slogan) !== null); - }, function (root) { - let rooti0 = fastn_dom.createKernel(root, fastn_dom.ElementKind.Text); - rooti0.setProperty(fastn_dom.PropertyKind.Role, inherited.get("types").get("copy_regular"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.StringValue, __args__.company_slogan, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Width, fastn_dom.Resizing.FillContainer, inherited); - rooti0.setProperty(fastn_dom.PropertyKind.MarginTop, fastn_dom.Length.Px(16), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.Color, inherited.get("colors").get("text_strong"), inherited); - rooti0.setProperty(fastn_dom.PropertyKind.TextAlign, fastn_dom.TextAlign.Center, inherited); - return rooti0; - }); - } - ]), inherited); - } - ]), inherited); - return parenti0; - } finally { - __fastn_package_name__ = __fastn_super_package_name__; - } -} -global["fastn_community_github_io_business_card__back"] = fastn_community_github_io_business_card__back; -let fastn_community_github_io_business_card__card = function (parent, inherited, args) -{ - let __fastn_super_package_name__ = __fastn_package_name__; - __fastn_package_name__ = "fastn_community_github_io_ssr_test"; - try { - let __args__ = { - contact_1: null, - contact_2: null, - email: null, - website: null, - address: null, - company_slogan: null, - }; - inherited = fastn_utils.getInheritedValues(__args__, inherited, args); - __args__ = fastn_utils.getArgs(__args__, args); - let parenti0 = fastn_community_github_io_business_card__display_card(parent, inherited, { - front: fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_community_github_io_business_card__front(root, inherited, { - name: __args__.name, - title: __args__.title, - company_name: __args__.company_name, - logo: __args__.logo, - contact_1: __args__.contact_1, - contact_2: __args__.contact_2, - email: __args__.email, - website: __args__.website, - address: __args__.address - }); - } - ]), - back: fastn.mutableList([function (root, inherited) { - let rooti0 = fastn_community_github_io_business_card__back(root, inherited, { - logo: __args__.logo, - company_slogan: __args__.company_slogan - }); - } - ]) - }); - return parenti0; - } finally { - __fastn_package_name__ = __fastn_super_package_name__; - } -} -global["fastn_community_github_io_business_card__card"] = fastn_community_github_io_business_card__card; +global["main"] = main; fastn_utils.createNestedObject(global, "fastn_community_github_io_ssr_test_assets__files.assets.ipsum_logo.svg", function () { let record = fastn.recordInstance({ }); @@ -881,8 +365,6 @@ record.set("dark", "-/fastn-community.github.io/ssr-test/assets/ipsum-logo-dark.svg"); return record; }()); -let fastn_community_github_io_business_card__display_card = global["fastn_community_github_io_business_card_lib__display_card"]; -global["fastn_community_github_io_business_card__display_card"] = fastn_community_github_io_business_card__display_card; fastn_dom.codeData.availableThemes["coldark-theme.dark"] = "code-theme-9A3284FD117DFF7CFD432FF860A5E14169FA592BC3DA4F5E8A6975143F5EA07F.css"; fastn_dom.codeData.availableThemes["coldark-theme.light"] = "code-theme-99CD7B013C96C4632F0AEA39AC265387B814AE85A7D33666A4AE4BEFF59016D0.css"; fastn_dom.codeData.availableThemes["coy-theme"] = "code-theme-B3AEA322EADEDA61F0E219845A0E9C8E73F6345E49362B46E6F52CEE40471248.css"; From 4ea5d3a145a1b83634c02c057c12f02449b61221 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Thu, 8 Feb 2024 11:25:42 +0530 Subject: [PATCH 07/12] minor fixes --- fastn-core/tests/19-bot-ssr/cmd.p1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastn-core/tests/19-bot-ssr/cmd.p1 b/fastn-core/tests/19-bot-ssr/cmd.p1 index b15161ca02..ff0aba0e12 100644 --- a/fastn-core/tests/19-bot-ssr/cmd.p1 +++ b/fastn-core/tests/19-bot-ssr/cmd.p1 @@ -4,9 +4,9 @@ output: .build -- stdout: -Updated package dependency +Updated package dependency. Starting fastn server ... -Updated package dependency +No packages updated. ### Server Started ### Go to: http://127.0.0.1:8000 Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) ... From 1120ff66091caa860b5390df55dac8a0a1e2ae29 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Thu, 8 Feb 2024 11:42:38 +0530 Subject: [PATCH 08/12] fixed tests --- fastn-core/tests/20-fastn-update-check/cmd.p1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastn-core/tests/20-fastn-update-check/cmd.p1 b/fastn-core/tests/20-fastn-update-check/cmd.p1 index 458afb8156..c3eacaad8c 100644 --- a/fastn-core/tests/20-fastn-update-check/cmd.p1 +++ b/fastn-core/tests/20-fastn-update-check/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test update --check +cmd: $FBT_CWD/../target/release/fastn --test update --check exit-code: 7 -- stdout: From 874dc55b0132585a71462a70855a279af8fb4d79 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Thu, 8 Feb 2024 12:01:20 +0530 Subject: [PATCH 09/12] fixed fbt tests --- fastn-core/tests/19-offline-build/cmd.p1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastn-core/tests/19-offline-build/cmd.p1 b/fastn-core/tests/19-offline-build/cmd.p1 index 56da43d49b..9d5e748c6f 100644 --- a/fastn-core/tests/19-offline-build/cmd.p1 +++ b/fastn-core/tests/19-offline-build/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: $FBT_CWD/../target/debug/fastn --test update && $FBT_CWD/../target/debug/fastn --test build --offline +cmd: $FBT_CWD/../target/release/fastn --test update && $FBT_CWD/../target/release/fastn --test build --offline output: .build -- stdout: From 2fa3b364f7b625298bd8a24501aba408924c0b50 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Thu, 8 Feb 2024 12:31:41 +0530 Subject: [PATCH 10/12] minor fixes --- fastn-core/tests/15-fpm-dependency-alias/cmd.p1 | 2 +- fastn-core/tests/19-offline-build/output/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fastn-core/tests/15-fpm-dependency-alias/cmd.p1 b/fastn-core/tests/15-fpm-dependency-alias/cmd.p1 index eecee14d9d..a9efdf7d05 100644 --- a/fastn-core/tests/15-fpm-dependency-alias/cmd.p1 +++ b/fastn-core/tests/15-fpm-dependency-alias/cmd.p1 @@ -1,5 +1,5 @@ -- fbt: -cmd: cd amitu && $FBT_CWD/../target/debug/fastn --test build --edition 2022 +cmd: cd amitu && $FBT_CWD/../target/release/fastn --test build --edition 2022 output: amitu/.build -- stdout: diff --git a/fastn-core/tests/19-offline-build/output/index.html b/fastn-core/tests/19-offline-build/output/index.html index c7e98cbe6c..40214767f6 100644 --- a/fastn-core/tests/19-offline-build/output/index.html +++ b/fastn-core/tests/19-offline-build/output/index.html @@ -16,7 +16,7 @@ - + From 4e7ac1e910cf947ae36dc95fd0d04a5fa473ec75 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Fri, 9 Feb 2024 00:11:02 +0530 Subject: [PATCH 11/12] fixed fbt tests --- fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/cmd.p1 | 3 +-- fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/FASTN.ftd | 0 .../input/assets/ipsum-logo-dark.svg | 0 .../{19-bot-ssr => 21-bot-ssr}/input/assets/ipsum-logo.svg | 0 fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/index.ftd | 0 .../{19-bot-ssr => 21-bot-ssr}/output/index-with-ssr.html | 0 .../{19-bot-ssr => 21-bot-ssr}/output/index-without-ssr.html | 0 fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/run-test.sh | 0 8 files changed, 1 insertion(+), 2 deletions(-) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/cmd.p1 (85%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/FASTN.ftd (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/assets/ipsum-logo-dark.svg (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/assets/ipsum-logo.svg (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/input/index.ftd (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/output/index-with-ssr.html (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/output/index-without-ssr.html (100%) rename fastn-core/tests/{19-bot-ssr => 21-bot-ssr}/run-test.sh (100%) diff --git a/fastn-core/tests/19-bot-ssr/cmd.p1 b/fastn-core/tests/21-bot-ssr/cmd.p1 similarity index 85% rename from fastn-core/tests/19-bot-ssr/cmd.p1 rename to fastn-core/tests/21-bot-ssr/cmd.p1 index ff0aba0e12..6c37508f39 100644 --- a/fastn-core/tests/19-bot-ssr/cmd.p1 +++ b/fastn-core/tests/21-bot-ssr/cmd.p1 @@ -1,10 +1,9 @@ -- fbt: -cmd: $FBT_CWD/tests/19-bot-ssr/run-test.sh +cmd: $FBT_CWD/tests/21-bot-ssr/run-test.sh output: .build -- stdout: -Updated package dependency. Starting fastn server ... No packages updated. ### Server Started ### diff --git a/fastn-core/tests/19-bot-ssr/input/FASTN.ftd b/fastn-core/tests/21-bot-ssr/input/FASTN.ftd similarity index 100% rename from fastn-core/tests/19-bot-ssr/input/FASTN.ftd rename to fastn-core/tests/21-bot-ssr/input/FASTN.ftd diff --git a/fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo-dark.svg b/fastn-core/tests/21-bot-ssr/input/assets/ipsum-logo-dark.svg similarity index 100% rename from fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo-dark.svg rename to fastn-core/tests/21-bot-ssr/input/assets/ipsum-logo-dark.svg diff --git a/fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo.svg b/fastn-core/tests/21-bot-ssr/input/assets/ipsum-logo.svg similarity index 100% rename from fastn-core/tests/19-bot-ssr/input/assets/ipsum-logo.svg rename to fastn-core/tests/21-bot-ssr/input/assets/ipsum-logo.svg diff --git a/fastn-core/tests/19-bot-ssr/input/index.ftd b/fastn-core/tests/21-bot-ssr/input/index.ftd similarity index 100% rename from fastn-core/tests/19-bot-ssr/input/index.ftd rename to fastn-core/tests/21-bot-ssr/input/index.ftd diff --git a/fastn-core/tests/19-bot-ssr/output/index-with-ssr.html b/fastn-core/tests/21-bot-ssr/output/index-with-ssr.html similarity index 100% rename from fastn-core/tests/19-bot-ssr/output/index-with-ssr.html rename to fastn-core/tests/21-bot-ssr/output/index-with-ssr.html diff --git a/fastn-core/tests/19-bot-ssr/output/index-without-ssr.html b/fastn-core/tests/21-bot-ssr/output/index-without-ssr.html similarity index 100% rename from fastn-core/tests/19-bot-ssr/output/index-without-ssr.html rename to fastn-core/tests/21-bot-ssr/output/index-without-ssr.html diff --git a/fastn-core/tests/19-bot-ssr/run-test.sh b/fastn-core/tests/21-bot-ssr/run-test.sh similarity index 100% rename from fastn-core/tests/19-bot-ssr/run-test.sh rename to fastn-core/tests/21-bot-ssr/run-test.sh From a1061812dfb94075280a8abe3b64be1333c29b68 Mon Sep 17 00:00:00 2001 From: Harsh Singh Date: Fri, 9 Feb 2024 18:21:29 +0530 Subject: [PATCH 12/12] minor fixes --- fastn-core/tests/21-bot-ssr/cmd.p1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastn-core/tests/21-bot-ssr/cmd.p1 b/fastn-core/tests/21-bot-ssr/cmd.p1 index 72fc84673a..3f5bf53a2c 100644 --- a/fastn-core/tests/21-bot-ssr/cmd.p1 +++ b/fastn-core/tests/21-bot-ssr/cmd.p1 @@ -8,6 +8,6 @@ Updated package dependency. Starting fastn server ... No packages updated. ### Server Started ### -Go to: http://127.0.0.1:8001 +Go to: http://127.0.0.1:8000 Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) ... Curling http://127.0.0.1:8000 with User Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123 Safari/537.36 ...