test: make extension packaging tests build-independent
- Use a temporary fake extension tree in packaging tests instead of relying on ignored generated bundles. - Keep coverage for Web Store manifest.key stripping and local-package key retention. - Fix plain pytest runs in clean CI checkouts where extension/background.js has not been built yet.
This commit is contained in:
@@ -11,8 +11,30 @@ def _load_packager():
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
def test_webstore_package_strips_manifest_key(tmp_path):
|
||||
def _fake_extension(tmp_path: Path) -> Path:
|
||||
extension = tmp_path / "extension"
|
||||
icons = extension / "icons"
|
||||
icons.mkdir(parents=True)
|
||||
(extension / "manifest.json").write_text(json.dumps({
|
||||
"manifest_version": 3,
|
||||
"name": "browser-cli",
|
||||
"version": "1.2.3",
|
||||
"key": "test-key",
|
||||
}), encoding="utf-8")
|
||||
for name in ("background.js", "content-dispatch.js", "content.js"):
|
||||
(extension / name).write_text("// generated test bundle\n", encoding="utf-8")
|
||||
(extension / "icon.svg").write_text("<svg />\n", encoding="utf-8")
|
||||
(icons / "icon-128.png").write_bytes(b"png")
|
||||
return extension
|
||||
|
||||
def _packager_with_fake_extension(tmp_path: Path):
|
||||
packager = _load_packager()
|
||||
packager.EXTENSION_DIR = _fake_extension(tmp_path)
|
||||
packager.DIST_DIR = tmp_path / "dist"
|
||||
return packager
|
||||
|
||||
def test_webstore_package_strips_manifest_key(tmp_path):
|
||||
packager = _packager_with_fake_extension(tmp_path)
|
||||
out = packager.package_extension(webstore=True, out=tmp_path / "webstore.zip")
|
||||
|
||||
with zipfile.ZipFile(out) as zf:
|
||||
@@ -26,10 +48,10 @@ def test_webstore_package_strips_manifest_key(tmp_path):
|
||||
assert "icons/icon-128.png" in names
|
||||
|
||||
def test_local_package_keeps_manifest_key(tmp_path):
|
||||
packager = _load_packager()
|
||||
packager = _packager_with_fake_extension(tmp_path)
|
||||
out = packager.package_extension(webstore=False, out=tmp_path / "local.zip")
|
||||
|
||||
with zipfile.ZipFile(out) as zf:
|
||||
manifest = json.loads(zf.read("manifest.json"))
|
||||
|
||||
assert "key" in manifest
|
||||
assert manifest["key"] == "test-key"
|
||||
|
||||
Reference in New Issue
Block a user