|
22 | 22 | import sys |
23 | 23 | import tempfile |
24 | 24 | import unittest |
| 25 | +import zipfile |
25 | 26 | from pathlib import Path |
| 27 | +from lib.theme_state import zip_astro_project |
26 | 28 |
|
27 | 29 | SCRIPT = Path(__file__).with_name('detect-project.py') |
28 | 30 | spec = importlib.util.spec_from_file_location('detect_project', SCRIPT) |
@@ -88,6 +90,35 @@ def test_an_html2wp_astro_export_is_prepared_by_copying(self): |
88 | 90 | import shutil |
89 | 91 | shutil.rmtree(ws, ignore_errors=True) |
90 | 92 |
|
| 93 | + def test_self_contained_export_survives_zip_roundtrip(self): |
| 94 | + with tempfile.TemporaryDirectory() as tmp: |
| 95 | + base = Path(tmp) |
| 96 | + project = write(base / 'astro-project', { |
| 97 | + 'package.json': pkg(deps={'astro': '5.18.2'}, build='astro build'), |
| 98 | + 'astro.config.mjs': 'export default {}', |
| 99 | + 'public/index.html': '<main>Home</main>', |
| 100 | + 'public/about.html': '<main>About</main>', |
| 101 | + 'dist/index.html': '<main>Home</main>', |
| 102 | + 'dist/about.html': '<main>About</main>', |
| 103 | + }) |
| 104 | + (project / 'src/fragments/bodies').mkdir(parents=True) |
| 105 | + (base / 'astro-report.json').write_text('{"pages":[],"warnings":[]}') |
| 106 | + archive = base / 'export.zip' |
| 107 | + self.assertTrue(zip_astro_project(project, archive, 'site-astro')) |
| 108 | + with zipfile.ZipFile(archive) as zf: |
| 109 | + zf.extractall(base / 'upload') |
| 110 | + imported = base / 'upload/site-astro' |
| 111 | + self.assertFalse((imported / 'src/fragments/bodies').exists()) |
| 112 | + found = dp.detect(base / 'upload') |
| 113 | + self.assertEqual((found['kind'], found['pages']), ('html2wp-astro', 2)) |
| 114 | + workspace = base / 'workspace' |
| 115 | + dp.prepare_astro_export(imported, workspace) |
| 116 | + self.assertEqual((workspace / 'astro-project/public/about.html').read_text(), '<main>About</main>') |
| 117 | + self.assertEqual((workspace / 'static-src/about.html').read_text(), '<main>About</main>') |
| 118 | + self.assertTrue((workspace / '.astro-project-imported').is_file()) |
| 119 | + (imported / '.html2wp/astro-report.json').unlink() |
| 120 | + self.assertEqual(dp.detect(imported)['kind'], 'static-site') |
| 121 | + |
91 | 122 | def test_a_buildable_app_is_a_web_app_and_tanstack_is_named(self): |
92 | 123 | write(self.root, {'package.json': pkg(deps={'@tanstack/react-start': '1', 'react': '19'})}) |
93 | 124 | found = self.kind() |
|
0 commit comments