1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
import unittest
from textwrap import dedent
import yaml
from mkdocs.tests.base import load_config
from mkdocs.utils import templates
class UtilsTemplatesTests(unittest.TestCase):
def test_script_tag(self):
cfg_yaml = dedent(
'''
extra_javascript:
- some_plain_javascript.js
- implicitly_as_module.mjs
- path: explicitly_as_module.mjs
type: module
- path: deferred_plain.js
defer: true
- path: scripts/async_module.mjs
type: module
async: true
- path: 'aaaaaa/"my script".mjs'
type: module
async: true
defer: true
- path: plain.mjs
'''
)
config = load_config(**yaml.safe_load(cfg_yaml))
config.extra_javascript.append('plain_string.mjs')
self.assertEqual(
[
str(templates.script_tag_filter({'page': None, 'base_url': 'here'}, item))
for item in config.extra_javascript
],
[
'<script src="here/some_plain_javascript.js"></script>',
'<script src="here/implicitly_as_module.mjs" type="module"></script>',
'<script src="here/explicitly_as_module.mjs" type="module"></script>',
'<script src="here/deferred_plain.js" defer></script>',
'<script src="here/scripts/async_module.mjs" type="module" async></script>',
'<script src="here/aaaaaa/"my script".mjs" type="module" defer async></script>',
'<script src="here/plain.mjs"></script>',
'<script src="here/plain_string.mjs"></script>',
],
)
|