Skip to content

Commit

Permalink
Add failing test for re-creating combined.min.js for new files
Browse files Browse the repository at this point in the history
  • Loading branch information
Siecje committed Feb 3, 2024
1 parent 79c11f3 commit a727a36
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion tests/test_preview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
import time
from types import TracebackType
import urllib3

from click.testing import CliRunner
from htmd.cli import preview
Expand Down Expand Up @@ -182,7 +183,7 @@ def test_preview_reload_js(run_start: CliRunner) -> None: # noqa: ARG001
while after == before:
try:
response = requests.get(url, timeout=0.1)
except requests.exceptions.ReadTimeout:
except (requests.exceptions.ReadTimeout, urllib3.exceptions.IncompleteRead):
# happens during restart
read_timeout = True
else:
Expand All @@ -191,3 +192,34 @@ def test_preview_reload_js(run_start: CliRunner) -> None: # noqa: ARG001
assert read_timeout
assert before != after
assert expected in after


def test_preview_reload_js_new_file(run_start: CliRunner) -> None: # noqa: ARG001
url = 'http://localhost:9090/static/combined.min.js'
new_js = 'document.getElementByTagName("body");'
expected = new_js

with run_preview():
response = requests.get(url, timeout=0.01)
assert response.status_code == 404
before = response.text
# Need to create before running preview since no .js files exist
js_path = Path('static') / 'script.js'
with js_path.open('w') as js_file:
js_file.write(new_js)

# Ensure new style is available after reload
read_timeout = False
after = before
while after == before:
try:
response = requests.get(url, timeout=0.1)
except requests.exceptions.ReadTimeout:
# happens during restart
read_timeout = True
else:
after = response.text

assert read_timeout is False
assert before != after
assert expected in after

0 comments on commit a727a36

Please sign in to comment.