Add cache-busted static asset URLs
This commit is contained in:
parent
99fd33f770
commit
df68aa95e9
2 changed files with 78 additions and 1 deletions
|
|
@ -32,6 +32,7 @@ from repub.web import (
|
|||
render_runs,
|
||||
render_settings,
|
||||
render_sources,
|
||||
versioned_static_asset_href,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -177,10 +178,12 @@ def test_root_get_serves_datastar_shim() -> None:
|
|||
|
||||
response = await client.get("/")
|
||||
body = await response.get_data(as_text=True)
|
||||
stylesheet_href = versioned_static_asset_href("app.css")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["ETag"]
|
||||
assert body.startswith("<!doctype html>")
|
||||
assert f'<link rel="stylesheet" href="{stylesheet_href}">' in body
|
||||
assert (
|
||||
'<script id="js" defer type="module" src="/static/datastar@1.0.0-RC.8.js"></script>'
|
||||
in body
|
||||
|
|
@ -200,6 +203,43 @@ def test_root_get_serves_datastar_shim() -> None:
|
|||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_versioned_static_asset_href_uses_truncated_file_hash() -> None:
|
||||
href = versioned_static_asset_href("app.css")
|
||||
|
||||
assert re.fullmatch(r"/static/app-[0-9a-f]{12}\.css", href)
|
||||
|
||||
|
||||
def test_versioned_static_asset_route_serves_registered_css_file() -> None:
|
||||
async def run() -> None:
|
||||
client = create_app().test_client()
|
||||
expected = (
|
||||
Path(__file__).resolve().parents[1] / "repub" / "static" / "app.css"
|
||||
).read_text(encoding="utf-8")
|
||||
|
||||
response = await client.get("/static/app-deadbeefcafe.css")
|
||||
body = await response.get_data(as_text=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.mimetype == "text/css"
|
||||
assert body == expected
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_versioned_static_asset_route_preserves_existing_hyphenated_files() -> None:
|
||||
async def run() -> None:
|
||||
client = create_app().test_client()
|
||||
|
||||
response = await client.get("/static/datastar@1.0.0-RC.8.js")
|
||||
body = await response.get_data(as_text=True)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.mimetype == "text/javascript"
|
||||
assert body.startswith("// Datastar v1.0.0-RC.8")
|
||||
|
||||
asyncio.run(run())
|
||||
|
||||
|
||||
def test_create_app_bootstraps_default_database_path(
|
||||
monkeypatch, tmp_path: Path
|
||||
) -> None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue