Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add standalone e2e tests #653

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: e2e-tests
name: e2e-dashboard-tests
on:
pull_request:
branches:
- main
paths:
- '.github/workflows/e2e-tests.yml'
- '.github/workflows/e2e-dashboard-tests.yml'
- '**.py'
- '**.ts'
- '**.tsx'
Expand Down Expand Up @@ -47,4 +47,4 @@ jobs:
run: playwright install

- name: Run e2e tests
run: pytest e2e_tests
run: pytest e2e_tests/test_dashboard
51 changes: 51 additions & 0 deletions .github/workflows/e2e-standalone-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: e2e-standalone-tests
on:
pull_request:
branches:
- main
paths:
- '.github/workflows/e2e-standalone-tests.yml'
- '**.py'
- '**.ts'
- '**.tsx'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
jobs:
test:
runs-on: ubuntu-20.04
strategy:
matrix:
optuna-version: ['optuna==2.10.0', 'git+https://github.com/optuna/optuna.git']
steps:
- uses: actions/checkout@v3

- name: Install Rust toolchains
uses: dtolnay/rust-toolchain@stable

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18'

- name: Setup Optuna ${{ matrix.optuna-version }}
run: |
python -m pip install --progress-bar off --upgrade pip setuptools
python -m pip install --progress-bar off --upgrade ${{ matrix.optuna-version }}

- name: Install dependencies
run: |
python -m pip install --progress-bar off .
python -m pip install --progress-bar off pytest-playwright

- name: Build standalone_app
run: make MODE="prd" standalone_app/public/bundle.js

- name: Install the required browsers
run: playwright install

- name: Run e2e tests
run: pytest e2e_tests/test_standalone
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from playwright.sync_api import Page
import pytest

from ..test_server import make_test_server
from ...test_server import make_test_server


def make_test_storage() -> optuna.storages.InMemoryStorage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from playwright.sync_api import Page
import pytest

from .test_server import make_test_server
from ..test_server import make_test_server


@pytest.fixture
Expand Down
28 changes: 28 additions & 0 deletions e2e_tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import http.server
import socket
import socketserver
import threading
from wsgiref.simple_server import make_server

Expand Down Expand Up @@ -33,3 +35,29 @@ def stop_server() -> None:
request.addfinalizer(stop_server)

return f"http://{addr}:{port}/dashboard"


def make_standalone_server(request: pytest.FixtureRequest) -> str:
addr = "127.0.0.1"
port = get_free_port()
directory = "./standalone_app/"

Handler = http.server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(
("", port), lambda *args, **kwargs: Handler(*args, directory=directory, **kwargs)
)

def serve_httpd():
httpd.serve_forever()

thread = threading.Thread(target=serve_httpd)
thread.start()

def stop_server() -> None:
httpd.shutdown()
httpd.server_close()
thread.join()

request.addfinalizer(stop_server)

return f"http://{addr}:{port}"
Empty file.
22 changes: 22 additions & 0 deletions e2e_tests/test_standalone/test_study_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from playwright.sync_api import Page
import pytest

from ..test_server import make_standalone_server


@pytest.fixture
def server_url(request: pytest.FixtureRequest) -> str:
return make_standalone_server(request)


def test_home(
page: Page,
server_url: str,
) -> None:
url = f"{server_url}"
page.goto(url)
element = page.get_by_role("heading")
assert element is not None
title = element.text_content()
assert title is not None
assert title == "Optuna Dashboard (Wasm ver.)"