Add a DummyWebpackLoader for running tests

This commit is contained in:
Bruno Alla 2023-02-03 19:08:13 +00:00
parent 826712d2b3
commit 93f2a1e87c
No known key found for this signature in database
3 changed files with 31 additions and 0 deletions

View File

@ -101,6 +101,13 @@ def remove_gulp_files():
def remove_webpack_files():
shutil.rmtree("webpack")
remove_vendors_js()
os.remove(
os.path.join(
"{{ cookiecutter.project_slug }}",
"utils",
"loaders.py",
)
)
def remove_vendors_js():

View File

@ -29,5 +29,13 @@ EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
# ------------------------------------------------------------------------------
TEMPLATES[0]["OPTIONS"]["debug"] = True # type: ignore # noqa F405
{%- if cookiecutter.frontend_pipeline == 'Webpack' %}
# django-webpack-loader
# ------------------------------------------------------------------------------
WEBPACK_LOADER["DEFAULT"][ # noqa F405
"LOADER_CLASS"
] = "{{cookiecutter.project_slug}}.utils.loaders.DummyWebpackLoader"
{%- endif %}
# Your stuff...
# ------------------------------------------------------------------------------

View File

@ -0,0 +1,16 @@
from webpack_loader.loader import WebpackLoader
class DummyWebpackLoader(WebpackLoader):
def get_bundle(self, _bundle_name: str):
"""
Dummy loader to run tests.
Needed to run tests without webpack stats file nor bundle built.
"""
return [
{
"name": "test.bundle.js",
"url": "http://localhost/static/bundles/test.bundle.js",
},
]