summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/test_storage.py
diff options
context:
space:
mode:
authorJames Bligh <618250+blighj@users.noreply.github.com>2022-12-07 09:56:00 +0000
committerGitHub <noreply@github.com>2022-12-07 10:56:00 +0100
commite44d348c99f0a449180399045ac54b3909121a03 (patch)
treed808d453195d7c206bc2094313e8c7d8b7c499a5 /tests/staticfiles_tests/test_storage.py
parent9ac97e7eb5a74f813012715c7598c8608e78e178 (diff)
Fixed #32319 -- Added ES module support to ManifestStaticFilesStorage.
Co-authored-by: James Bligh <james.bligh@silvercloudhealth.com>
Diffstat (limited to 'tests/staticfiles_tests/test_storage.py')
-rw-r--r--tests/staticfiles_tests/test_storage.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index 16bb556d4f..077d14bcc4 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -177,6 +177,52 @@ 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"],