Skip to content

Commit 09e5d3b

Browse files
committed
Updated test cases to cover new features
1 parent ce5769d commit 09e5d3b

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ tests/venv/
7070
tests/venv3/
7171
tests/node_modules/
7272
tests/assets/bundles/
73-
tests/assets/webpack-stats.json
73+
tests/webpack-stats.json

tests/app/templates/home.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% load render_bundle from webpack_loader %}
1+
{% load render_bundle webpack_static from webpack_loader %}
22
<!DOCTYPE html>
33
<html>
44
<head>
@@ -8,6 +8,7 @@
88
</head>
99

1010
<body>
11+
<img src="{% webpack_static 'my-image.png' %}"/>
1112
<div id="react-app"></div>
1213
{% render_bundle 'main' 'js' %}
1314
</body>

tests/app/tests/test_webpack.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def test_simple_and_css_extract(self):
4444
self.assertEqual(main[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/main.js'))
4545
self.assertEqual(main[1]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/styles.css'))
4646

47+
def test_static_url(self):
48+
self.compile_bundles('webpack.config.publicPath.js')
49+
assets = get_assets()
50+
self.assertEqual(assets['status'], 'done')
51+
self.assertEqual(assets['publicPath'], 'http://custom-static-host.com/')
52+
4753
def test_code_spliting(self):
4854
self.compile_bundles('webpack.config.split.js')
4955
assets = get_assets()
@@ -60,6 +66,21 @@ def test_code_spliting(self):
6066
vendor = chunks['vendor']
6167
self.assertEqual(vendor[0]['path'], os.path.join(settings.BASE_DIR, 'assets/bundles/vendor.js'))
6268

69+
def test_templatetags(self):
70+
self.compile_bundles('webpack.config.simple.js')
71+
view = TemplateView.as_view(template_name='home.html')
72+
request = self.factory.get('/')
73+
result = view(request)
74+
self.assertIn('<link type="text/css" href="/static/bundles/styles.css" rel="stylesheet">', result.rendered_content)
75+
self.assertIn('<script type="text/javascript" src="/static/bundles/main.js"></script>', result.rendered_content)
76+
77+
78+
self.compile_bundles('webpack.config.publicPath.js')
79+
view = TemplateView.as_view(template_name='home.html')
80+
request = self.factory.get('/')
81+
result = view(request)
82+
self.assertIn('<img src="http://custom-static-host.com/my-image.png"/>', result.rendered_content)
83+
6384
def test_jinja2(self):
6485
self.compile_bundles('webpack.config.simple.js')
6586
view = TemplateView.as_view(template_name='home.jinja')

tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"react": "^0.13.3",
1616
"style-loader": "^0.12.3",
1717
"webpack": "^1.9.8",
18-
"webpack-bundle-tracker": "0.0.5",
18+
"webpack-bundle-tracker": "0.0.8",
1919
"webpack-dev-server": "^1.9.0",
2020
"webpack-split-by-path": "0.0.1"
2121
}

tests/webpack-stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"status":"done","chunks":{"main":[{"name":"main.js","path":"/Users/owais/Projects/django-webpack-loader/tests/assets/bundles/main.js"},{"name":"styles.css","path":"/Users/owais/Projects/django-webpack-loader/tests/assets/bundles/styles.css"}]}}
1+
{"status":"done","chunks":{"main":[{"name":"main.js","publicPath":"http://custom-static-host.com/main.js","path":"/Users/owais/Projects/django-webpack-loader/tests/assets/bundles/main.js"},{"name":"styles.css","publicPath":"http://custom-static-host.com/styles.css","path":"/Users/owais/Projects/django-webpack-loader/tests/assets/bundles/styles.css"}]},"publicPath":"http://custom-static-host.com/"}

tests/webpack.config.publicPath.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var config = require("./webpack.config.simple.js");
2+
3+
config.output.publicPath = "http://custom-static-host.com/"
4+
5+
module.exports = config;

tests/webpack.config.simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
entry: './assets/js/index',
1010
output: {
1111
path: path.resolve('./assets/bundles/'),
12-
filename: "[name].js",
12+
filename: "[name].js"
1313
},
1414

1515
plugins: [

0 commit comments

Comments
 (0)