diff --git a/tests/unit/viahtml/patch_test.py b/tests/unit/viahtml/patch_test.py index a080124f..5000614d 100644 --- a/tests/unit/viahtml/patch_test.py +++ b/tests/unit/viahtml/patch_test.py @@ -1,12 +1,22 @@ # pylint:disable=protected-access -from unittest.mock import create_autospec, sentinel +from unittest.mock import create_autospec, patch, sentinel import pytest +from pywb.rewrite.content_rewriter import RewriteInfo +from pywb.rewrite.default_rewriter import DefaultRewriter +from pywb.rewrite.html_rewriter import HTMLRewriter from pywb.rewrite.url_rewriter import UrlRewriter from viahtml.hooks import Hooks -from viahtml.patch import _PatchedHTMLRewriter +from viahtml.patch import ( + ESM_MOD, + ESM_TEXT_TYPE, + _ESMWombatProxyRewriter, + _patch_esm_rewriting, + _PatchedHTMLRewriter, + _resolve_text_type, +) class TestRewriteLinkHref: @@ -17,6 +27,13 @@ class TestRewriteLinkHref: # pywb's /id_/ endpoint in order to disable any rewriting of # manifest files. ("https://example.com", [("rel", "manifest")], "id_/https://example.com"), + # Links that preload an ES module go through the module modifier, so + # that the module isn't served with pywb's classic script wrapper. + ( + "https://example.com", + [("rel", "modulepreload")], + "esm_/https://example.com", + ), # Any other links get sent to the rw_mod endpoint which will rewrite # the file as usual. ("https://example.com", [], "rw_mod/https://example.com"), @@ -87,6 +104,45 @@ def test_rewrite_tag_attrs_if_modify_tag_attrs_returns_stop_False( # It returns what pywb's _rewrite_tag_attrs returned. assert returned is True + def test_it_sends_module_scripts_to_the_module_modifier( + self, patched_html_rewriter + ): + self.returning_module_script(patched_html_rewriter) + + patched_html_rewriter._rewrite_tag_attrs("script", sentinel.tag_attrs) + + assert ( + self.written(patched_html_rewriter) + == '