Skip to content

Commit

Permalink
Merge pull request #653 from keisuke-umezawa/feature/add-standalone-d…
Browse files Browse the repository at this point in the history
…b-test

Add standalone e2e tests
  • Loading branch information
keisuke-umezawa authored Oct 15, 2023
2 parents 96a0af3 + 844ac81 commit 2fbfe90
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 5 deletions.
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
File renamed without changes.
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.)"

0 comments on commit 2fbfe90

Please sign in to comment.