mirror of
https://github.com/django/django.git
synced 2025-11-01 12:25:37 +00:00
Fixed #32319 -- Added ES module support to ManifestStaticFilesStorage.
This commit is contained in:
parent
781b44240a
commit
91e21836f6
8 changed files with 96 additions and 0 deletions
|
|
@ -159,6 +159,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.91b9cf9935da.js')
|
||||
tests = [
|
||||
# Relative imports.
|
||||
b'import testConst from "./module_test.d489af3cf882.js";',
|
||||
b'import relativeModule from "../nested/js/nested.866475c46bb4.js";',
|
||||
b'import { firstConst, secondConst } from "./module_test.d489af3cf882.js";',
|
||||
# Absolute import.
|
||||
b'import rootConst from "/static/absolute_root.5586327fe78c.js";',
|
||||
# Dynamic import.
|
||||
b'const dynamicModule = import("./module_test.d489af3cf882.js");',
|
||||
# Creating a module object.
|
||||
b'import * as NewModule from "./module_test.d489af3cf882.js";',
|
||||
# Aliases.
|
||||
b'import { testConst as alias } from "./module_test.d489af3cf882.js";',
|
||||
b'import {\n'
|
||||
b' firstVar as firstVarAlias,\n'
|
||||
b' secondVar as secondVarAlias\n'
|
||||
b'} from "./module_test.d489af3cf882.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.91b9cf9935da.js')
|
||||
tests = [
|
||||
b'export * from "./module_test.d489af3cf882.js";',
|
||||
b'export { testConst } from "./module_test.d489af3cf882.js";',
|
||||
b'export {\n'
|
||||
b' firstVar as firstVarAlias,\n'
|
||||
b' secondVar as secondVarAlias\n'
|
||||
b'} from "./module_test.d489af3cf882.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'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue