From 82f60f3d753e9b3e6321a120b2568042d6a2afb4 Mon Sep 17 00:00:00 2001 From: omicron Date: Fri, 28 Aug 2026 01:44:38 +0200 Subject: [PATCH] Set up e2e testing --- .gitignore | 2 ++ tests/data/sites/main/config.yml | 3 ++ tests/data/sites/main/content/first_post.md | 10 +++++++ tests/e2e/test_success.py | 31 +++++++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/data/sites/main/config.yml create mode 100644 tests/data/sites/main/content/first_post.md create mode 100644 tests/e2e/test_success.py diff --git a/.gitignore b/.gitignore index acc0e63..577adf0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__ *.pyc .coverage htmlcov/ +tests/data/sites/*/output/ +tests/data/sites/*/build.log diff --git a/tests/data/sites/main/config.yml b/tests/data/sites/main/config.yml new file mode 100644 index 0000000..a2420b5 --- /dev/null +++ b/tests/data/sites/main/config.yml @@ -0,0 +1,3 @@ +name: Main Test Site +base_url: http://127.0.0.1:8000 +template: plain diff --git a/tests/data/sites/main/content/first_post.md b/tests/data/sites/main/content/first_post.md new file mode 100644 index 0000000..a52b8e5 --- /dev/null +++ b/tests/data/sites/main/content/first_post.md @@ -0,0 +1,10 @@ +--- +type: article +section: posts +slug: first-post +title: First Post +date: 2026-08-28 +tags: [meta] +--- +Welcome to the test site. This site will contain some test content for the +static site generator, the content won't matter a lot. diff --git a/tests/e2e/test_success.py b/tests/e2e/test_success.py new file mode 100644 index 0000000..b11506c --- /dev/null +++ b/tests/e2e/test_success.py @@ -0,0 +1,31 @@ +import shutil +import subprocess +from pathlib import Path + +import pytest + +MAIN_SITE = Path(__file__).parent.parent / "data" / "sites" / "main" + + +@pytest.fixture(scope="module") +def built_site(tmp_path_factory): + site_dir = tmp_path_factory.mktemp("main") + shutil.copytree( + MAIN_SITE, + site_dir, + dirs_exist_ok=True, + ignore=shutil.ignore_patterns("output", "build.log"), + ) + result = subprocess.run( + ["ossg", "--site", str(site_dir), "build"], + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stderr + return site_dir / "output" + + +def test_article_renders(built_site): + output = built_site / "posts" / "first-post" / "index.html" + assert output.exists() + assert "First Post" in output.read_text()