chore(trading): run against local console (#5500)
This commit is contained in:
parent
bb2184498f
commit
08c57b6759
@ -87,10 +87,9 @@ docker build -f docker/node-outside-docker.Dockerfile --build-arg APP=trading --
|
|||||||
|
|
||||||
## Running Tests 🧪
|
## Running Tests 🧪
|
||||||
|
|
||||||
Before running make sure the docker daemon is runnign so that the app can be served.
|
Before running make sure the docker daemon is running.
|
||||||
|
|
||||||
To run a specific test, use the `-k` option followed by the name of the test.
|
To run a specific test, use the `-k` option followed by the name of the test.
|
||||||
|
|
||||||
Run all tests:
|
Run all tests:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -109,6 +108,25 @@ Run from anywhere:
|
|||||||
yarn trading:test -- "test_name" -s --headed
|
yarn trading:test -- "test_name" -s --headed
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Run using your locally served console:
|
||||||
|
|
||||||
|
Within one terminal
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn nx build trading
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yarn nx serve trading
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Once console is served you can use the flag --local-server
|
||||||
|
|
||||||
|
```bash
|
||||||
|
poetry run pytest -k "test_name" -s --headed --local-server
|
||||||
|
```
|
||||||
|
|
||||||
## Running Tests in Parallel 🔢
|
## Running Tests in Parallel 🔢
|
||||||
|
|
||||||
To run tests in parallel, use the `--numprocesses auto` option. The `--dist loadfile` setting ensures that multiple runners are not assigned to a single test file.
|
To run tests in parallel, use the `--numprocesses auto` option. The `--dist loadfile` setting ensures that multiple runners are not assigned to a single test file.
|
||||||
|
@ -7,7 +7,6 @@ import time
|
|||||||
import docker
|
import docker
|
||||||
import http.server
|
import http.server
|
||||||
|
|
||||||
|
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from vega_sim.null_service import VegaServiceNull
|
from vega_sim.null_service import VegaServiceNull
|
||||||
from playwright.sync_api import Browser, Page
|
from playwright.sync_api import Browser, Page
|
||||||
@ -102,11 +101,23 @@ def init_vega(request=None):
|
|||||||
logger.info(f"Removing container {container.id}")
|
logger.info(f"Removing container {container.id}")
|
||||||
container.remove()
|
container.remove()
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--local-server", action="store_true", default=False,
|
||||||
|
help="Build and serve locally instead of using a container"
|
||||||
|
)
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def local_server(pytestconfig):
|
||||||
|
return pytestconfig.getoption("--local-server")
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest):
|
def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRequest, local_server: bool):
|
||||||
|
server_port = "4200" if local_server else str(vega.console_port)
|
||||||
with browser.new_context(
|
with browser.new_context(
|
||||||
viewport={"width": 1920, "height": 1080},
|
viewport={"width": 1920, "height": 1080},
|
||||||
base_url=f"http://localhost:{vega.console_port}",
|
base_url=f"http://localhost:{server_port}",
|
||||||
) as context, context.new_page() as page:
|
) as context, context.new_page() as page:
|
||||||
context.tracing.start(screenshots=True, snapshots=True, sources=True)
|
context.tracing.start(screenshots=True, snapshots=True, sources=True)
|
||||||
try:
|
try:
|
||||||
@ -115,7 +126,7 @@ def init_page(vega: VegaServiceNull, browser: Browser, request: pytest.FixtureRe
|
|||||||
while attempts < 100:
|
while attempts < 100:
|
||||||
try:
|
try:
|
||||||
code = requests.get(
|
code = requests.get(
|
||||||
f"http://localhost:{vega.console_port}/"
|
f"http://localhost:{server_port}/"
|
||||||
).status_code
|
).status_code
|
||||||
if code == 200:
|
if code == 200:
|
||||||
break
|
break
|
||||||
@ -161,8 +172,8 @@ def vega(request):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def page(vega, browser, request):
|
def page(vega, browser, request, local_server):
|
||||||
with init_page(vega, browser, request) as page_instance:
|
with init_page(vega, browser, request, local_server) as page_instance:
|
||||||
yield page_instance
|
yield page_instance
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ def vega():
|
|||||||
|
|
||||||
# setting up everything in this single fixture, as all of the tests need the same setup, so no point in creating separate ones
|
# setting up everything in this single fixture, as all of the tests need the same setup, so no point in creating separate ones
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request):
|
def page(vega, browser, request, local_server):
|
||||||
with init_page(vega, browser, request) as page:
|
with init_page(vega, browser, request, local_server) as page:
|
||||||
setup_continuous_market(vega)
|
setup_continuous_market(vega)
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
page.goto("/")
|
page.goto("/")
|
||||||
|
@ -12,8 +12,8 @@ def vega(request):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request):
|
def page(vega, browser, request, local_server):
|
||||||
with init_page(vega, browser, request) as page:
|
with init_page(vega, browser, request, local_server) as page:
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
page.goto("/#/markets/all")
|
page.goto("/#/markets/all")
|
||||||
yield page
|
yield page
|
||||||
|
@ -12,8 +12,8 @@ def vega():
|
|||||||
|
|
||||||
# we can reuse single page instance in all tests
|
# we can reuse single page instance in all tests
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request):
|
def page(vega, browser, request, local_server):
|
||||||
with init_page(vega, browser, request) as page:
|
with init_page(vega, browser, request, local_server) as page:
|
||||||
yield page
|
yield page
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ def markets(vega: VegaService):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="module")
|
@pytest.fixture(scope="module")
|
||||||
def page(vega, browser, request):
|
def page(vega, browser, request, local_server):
|
||||||
with init_page(vega, browser, request) as page:
|
with init_page(vega, browser, request, local_server) as page:
|
||||||
risk_accepted_setup(page)
|
risk_accepted_setup(page)
|
||||||
auth_setup(vega, page)
|
auth_setup(vega, page)
|
||||||
page.goto("/")
|
page.goto("/")
|
||||||
|
Loading…
Reference in New Issue
Block a user