Skip to content

Commit

Permalink
Merge pull request #2913 from kobotoolbox/issue-2890
Browse files Browse the repository at this point in the history
Fix `http://kpi/browser_tests/` URL to run mocha tests
  • Loading branch information
jnm authored Dec 29, 2020
2 parents c79e5f9 + 038dfc6 commit 06c0aa4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions kobo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def __init__(self, *args, **kwargs):
os.path.join(BASE_DIR, 'jsapp'),
os.path.join(BASE_DIR, 'static'),
('mocha', os.path.join(BASE_DIR, 'node_modules', 'mocha'),),
('chai', os.path.join(BASE_DIR, 'node_modules', 'chai'),),
)

if os.path.exists(os.path.join(BASE_DIR, 'dkobo', 'jsapp')):
Expand Down
9 changes: 8 additions & 1 deletion kpi/templates/browser_tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
<title>KPI tests</title>
<link rel="stylesheet" href="{% static 'mocha/mocha.css' %}"/>
<script src="{% static 'mocha/mocha.js' %}"></script>
<script src="{% static 'chai/chai.js' %}"></script>
</head>
<body>
<script>
// need "t" defined for tests to pass
function t (str) { return str; }
var expect = chai.expect;
</script>
<script>mocha.setup('bdd')</script>
<div id="mocha"></div>
{% render_bundle 'tests' 'js' %}
{% render_bundle 'browsertests' 'js' %}
{% render_bundle 'vendors' 'js' %}
<script>mocha.run();</script>
</body>
</html>
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@
"zxcvbn": "^4.4.2"
},
"scripts": {
"build": "webpack --config webpack/prod.config.js --colors",
"build-production": "npm run build && echo 'WARNING: npm run build-production DEPRECATED! PLEASE USE npm run build INSTEAD'",
"build": "webpack --config webpack/prod.config.js",
"watch": "webpack-dev-server --config webpack/dev.server.js",
"test": "webpack --config webpack/test.config.js --colors && mocha-chrome test/tests.html",
"test": "webpack --config webpack/test.config.js && mocha-chrome test/tests.html",
"lint": "eslint --ext .es6 \"jsapp/js/**/*\"",
"show-icons": "opn jsapp/fonts/k-icons.html",
"generate-icons": "node ./scripts/generate_icons.js",
Expand Down
6 changes: 4 additions & 2 deletions test/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
<body>
<div id="mocha"></div>
<script>
expect = chai.expect;
var expect = chai.expect;
// need "t" defined for tests to pass
function t (str) { return str; }
</script>
<script src="./compiled/app.js"></script>
<script src="./compiled/webpack-built-tests.js"></script>
<script>
mocha.run();
</script>
Expand Down
2 changes: 1 addition & 1 deletion webpack/dev.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = WebpackCommon({
},
entry: {
app: ['react-hot-loader/patch', './jsapp/js/main.es6'],
tests: path.resolve(__dirname, '../test/index.js')
browsertests: path.resolve(__dirname, '../test/index.js')
},
output: {
library: 'KPI',
Expand Down
2 changes: 1 addition & 1 deletion webpack/prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = WebpackCommon({
},
entry: {
app: './jsapp/js/main.es6',
tests: path.resolve(__dirname, '../test/index.js')
browsertests: path.resolve(__dirname, '../test/index.js')
},
output: {
path: path.resolve(__dirname, '../jsapp/compiled/'),
Expand Down
2 changes: 1 addition & 1 deletion webpack/test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = WebpackCommon({
output: {
library: 'tests',
path: path.resolve(__dirname, '../test/compiled/'),
filename: 'app.js'
filename: 'webpack-built-tests.js'
},
// mainly for hiding stylelint output
stats: {
Expand Down

0 comments on commit 06c0aa4

Please sign in to comment.