diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-18 14:05:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-18 14:05:41 +0100 |
commit | e10c1688f96e3b2d202fe401472b7b25f6105969 (patch) | |
tree | 741b2ca1f5638427b0da833e157a8f5991689aec /tests/staticfiles_tests | |
parent | 2ffa815c734e12262a3cb8ce5664f297128ae47f (diff) | |
download | django-e10c1688f96e3b2d202fe401472b7b25f6105969.tar.gz |
Fixed #34322 -- Made ES module support to ManifestStaticFilesStorage optional.
Co-authored-by: Author: Claude Paroz <claude@2xlibre.net>
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/test_storage.py | 108 |
1 files changed, 62 insertions, 46 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py index 759582122d..2202a5bc07 100644 --- a/tests/staticfiles_tests/test_storage.py +++ b/tests/staticfiles_tests/test_storage.py @@ -177,52 +177,6 @@ class TestHashedFiles: self.assertIn(b"https://", relfile.read()) self.assertPostCondition() - def test_module_import(self): - relpath = self.hashed_file_path("cached/module.js") - self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") - tests = [ - # Relative imports. - b'import testConst from "./module_test.477bbebe77f0.js";', - b'import relativeModule from "../nested/js/nested.866475c46bb4.js";', - b'import { firstConst, secondConst } from "./module_test.477bbebe77f0.js";', - # Absolute import. - b'import rootConst from "/static/absolute_root.5586327fe78c.js";', - # Dynamic import. - b'const dynamicModule = import("./module_test.477bbebe77f0.js");', - # Creating a module object. - b'import * as NewModule from "./module_test.477bbebe77f0.js";', - # Aliases. - b'import { testConst as alias } from "./module_test.477bbebe77f0.js";', - b"import {\n" - b" firstVar1 as firstVarAlias,\n" - b" $second_var_2 as secondVarAlias\n" - b'} from "./module_test.477bbebe77f0.js";', - ] - with storage.staticfiles_storage.open(relpath) as relfile: - content = relfile.read() - for module_import in tests: - with self.subTest(module_import=module_import): - self.assertIn(module_import, content) - self.assertPostCondition() - - def test_aggregating_modules(self): - relpath = self.hashed_file_path("cached/module.js") - self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") - tests = [ - b'export * from "./module_test.477bbebe77f0.js";', - b'export { testConst } from "./module_test.477bbebe77f0.js";', - b"export {\n" - b" firstVar as firstVarAlias,\n" - b" secondVar as secondVarAlias\n" - b'} from "./module_test.477bbebe77f0.js";', - ] - with storage.staticfiles_storage.open(relpath) as relfile: - content = relfile.read() - for module_import in tests: - with self.subTest(module_import=module_import): - self.assertIn(module_import, content) - self.assertPostCondition() - @override_settings( STATICFILES_DIRS=[os.path.join(TEST_ROOT, "project", "loop")], STATICFILES_FINDERS=["django.contrib.staticfiles.finders.FileSystemFinder"], @@ -646,6 +600,68 @@ class TestCollectionSimpleStorage(CollectionTestCase): self.assertIn(b"other.deploy12345.css", content) +class JSModuleImportAggregationManifestStorage(storage.ManifestStaticFilesStorage): + support_js_module_import_aggregation = True + + +@override_settings( + STORAGES={ + STATICFILES_STORAGE_ALIAS: { + "BACKEND": ( + "staticfiles_tests.test_storage." + "JSModuleImportAggregationManifestStorage" + ), + }, + } +) +class TestCollectionJSModuleImportAggregationManifestStorage(CollectionTestCase): + hashed_file_path = hashed_file_path + + def test_module_import(self): + relpath = self.hashed_file_path("cached/module.js") + self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") + tests = [ + # Relative imports. + b'import testConst from "./module_test.477bbebe77f0.js";', + b'import relativeModule from "../nested/js/nested.866475c46bb4.js";', + b'import { firstConst, secondConst } from "./module_test.477bbebe77f0.js";', + # Absolute import. + b'import rootConst from "/static/absolute_root.5586327fe78c.js";', + # Dynamic import. + b'const dynamicModule = import("./module_test.477bbebe77f0.js");', + # Creating a module object. + b'import * as NewModule from "./module_test.477bbebe77f0.js";', + # Aliases. + b'import { testConst as alias } from "./module_test.477bbebe77f0.js";', + b"import {\n" + b" firstVar1 as firstVarAlias,\n" + b" $second_var_2 as secondVarAlias\n" + b'} from "./module_test.477bbebe77f0.js";', + ] + with storage.staticfiles_storage.open(relpath) as relfile: + content = relfile.read() + for module_import in tests: + with self.subTest(module_import=module_import): + self.assertIn(module_import, content) + + def test_aggregating_modules(self): + relpath = self.hashed_file_path("cached/module.js") + self.assertEqual(relpath, "cached/module.55fd6938fbc5.js") + tests = [ + b'export * from "./module_test.477bbebe77f0.js";', + b'export { testConst } from "./module_test.477bbebe77f0.js";', + b"export {\n" + b" firstVar as firstVarAlias,\n" + b" secondVar as secondVarAlias\n" + b'} from "./module_test.477bbebe77f0.js";', + ] + with storage.staticfiles_storage.open(relpath) as relfile: + content = relfile.read() + for module_import in tests: + with self.subTest(module_import=module_import): + self.assertIn(module_import, content) + + class CustomManifestStorage(storage.ManifestStaticFilesStorage): def __init__(self, *args, manifest_storage=None, **kwargs): manifest_storage = storage.StaticFilesStorage( |