Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/app/tests/test_webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
WebpackLoaderBadStatsError
)
from webpack_loader.utils import get_loader
from webpack_loader.templatetags.webpack_loader import render_bundle


BUNDLE_PATH = os.path.join(settings.BASE_DIR, 'assets/bundles/')
Expand Down Expand Up @@ -166,6 +167,20 @@ def test_missing_stats_file(self):
).format(stats_file)
self.assertIn(expected, str(e))

def test_missin_stats_file_template_tag_render_bundle(self):
stats_file = settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE']
if os.path.exists(stats_file):
os.remove(stats_file)
expected = '<script>console.error("{} - {}");</script>'.format(
'main',
'Error reading {0}. Are you sure webpack has generated the '
'file and the path is correct?'.format(stats_file)
)
self.assertEquals(
render_bundle('main'),
expected
)

def test_bad_status_in_production(self):
with open(
settings.WEBPACK_LOADER[DEFAULT_CONFIG]['STATS_FILE'], 'w'
Expand Down
8 changes: 7 additions & 1 deletion webpack_loader/templatetags/webpack_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ def _get_bundle(bundle_name, extension, config):

@register.simple_tag
def render_bundle(bundle_name, extension=None, config='DEFAULT'):
return render_as_tags(_get_bundle(bundle_name, extension, config))
try:
return render_as_tags(_get_bundle(bundle_name, extension, config))
except (IOError, KeyError) as e:
return '<script>console.error("{} - {}");</script>'.format(
bundle_name,
e
)


@register.simple_tag
Expand Down