diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a72cd0..84e333a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -155,6 +155,8 @@ jobs: run: cmake --build build --parallel $(nproc) --config Release - name: Run headless test run: pushd build && ctest --output-on-failure + - name: Run integration test on sample app + run: pushd build/examples && ./run.sh && python3 run-tests-selenium.py build-on-windows-for-cppcli: runs-on: windows-latest diff --git a/bin/djinni b/bin/djinni index d5e3154..9629bab 100755 Binary files a/bin/djinni and b/bin/djinni differ diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c5dcaec..1aba9a3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -36,6 +36,7 @@ add_djinni_target(DjinniTextSort WASM_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/wasm" TS_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/ts" TS_MODULE "example" + TS_SUPPORT_FILES_OUT "${CMAKE_CURRENT_BINARY_DIR}/ts-support-lib" YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml" YAML_PREFIX "test_" diff --git a/examples/ts/run-tests-selenium.py b/examples/ts/run-tests-selenium.py new file mode 100755 index 0000000..42f7e18 --- /dev/null +++ b/examples/ts/run-tests-selenium.py @@ -0,0 +1,53 @@ +#! /usr/bin/env python3 + +from http.server import HTTPServer, SimpleHTTPRequestHandler +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.chrome.service import Service +import sys +import time +import threading + +port = "8050" +httpd = HTTPServer(("127.0.0.1", int(port)), SimpleHTTPRequestHandler) + +def run_server(): + print("Serving HTTP on localhost port " + port + " (http://localhost:" + port + "/) ...") + httpd.serve_forever() + +server_thread = threading.Thread(target=run_server) +server_thread.start() + +service = Service(executable_path=r'/usr/bin/chromedriver') +options = webdriver.ChromeOptions() +options.add_argument('--headless') +options.add_argument('--no-sandbox') +options.add_argument('--disable-dev-shm-usage') +options.add_argument('--disable-gpu') +driver = webdriver.Chrome(service=service, options=options) +print(f"connecting web driver to http://localhost:{port}/") +driver.get(f"http://localhost:{port}/demo.html") +asc_button = driver.find_element(By.ID, "btnAsc") +desc_button = driver.find_element(By.ID, "btnDesc") + +asc_button.click() +print("Wait for Asc button press") +time.sleep(0.5) +value = driver.find_element(By.ID, "txt").get_attribute("value") +is_ascending_ok = value == "item1\nitem2\nitem3\nitem4\nitem5" +print(f"text area on Sort Asc pressed:\n{value}") +desc_button.click() +print("Wait for Desc button press") +time.sleep(0.5) +value = driver.find_element(By.ID, "txt").get_attribute("value") +print(f"text area on Sort Desc pressed:\n{value}") +is_descending_ok = value == "item5\nitem4\nitem3\nitem2\nitem1" + +driver.quit() +httpd.shutdown() +server_thread.join() +if is_ascending_ok and is_descending_ok: + exit(0) +print(f"is_ascending_ok = {is_ascending_ok}") +print(f"is_descending_ok = {is_descending_ok}") +exit(1) diff --git a/examples/ts/run.sh b/examples/ts/run.sh index bdbfd1e..c6a0082 100755 --- a/examples/ts/run.sh +++ b/examples/ts/run.sh @@ -2,5 +2,3 @@ set -eu tsc browserify demo.js -o bundle.js -sleep 1 && python3 -mwebbrowser http://localhost:8000/demo.html & -python3 -m http.server diff --git a/test-suite/CMakeLists.txt b/test-suite/CMakeLists.txt index d7ba1ef..7e4aa2e 100644 --- a/test-suite/CMakeLists.txt +++ b/test-suite/CMakeLists.txt @@ -37,6 +37,7 @@ add_djinni_target(DjinniAllTests WASM_NAMESPACE "testsuite" TS_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/ts" TS_MODULE "test" + TS_SUPPORT_FILES_OUT "${CMAKE_CURRENT_BINARY_DIR}/ts-support-lib" YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml" YAML_PREFIX "test_" @@ -80,7 +81,6 @@ add_djinni_target(DjinniWCharTests WASM_NAMESPACE "testsuite" TS_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/ts" TS_MODULE "test_wchar" - TS_SUPPORT_FILES_OUT "${CMAKE_CURRENT_BINARY_DIR}/ts-support-lib" YAML_OUT "${CMAKE_CURRENT_BINARY_DIR}/generated-src/yaml" YAML_PREFIX "test_"