Skip to content

Commit

Permalink
Fixed render_bundle tag when the stats file does not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yograterol committed May 20, 2016
1 parent 9eae37f commit f70e872
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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 as e:
return '<script>console.error("{} - {}");</script>'.format(
bundle_name,
e
)


@register.simple_tag
Expand Down

0 comments on commit f70e872

Please sign in to comment.