Added JSHint to the tests.

master
Pacman Ghost 6 years ago
parent dc535d9d6d
commit e997caacf4
  1. 0
      vasl_templates/webapp/static/jinja/jinja.js
  2. 0
      vasl_templates/webapp/static/jquery/jquery-3.3.1.min.js
  3. 11
      vasl_templates/webapp/static/main.js
  4. 4
      vasl_templates/webapp/templates/main.html
  5. 44
      vasl_templates/webapp/tests/test_jshint.py

@ -4,7 +4,7 @@ var gDefaultTemplates = {} ;
// if they're not set, but they're really, really, really expected to be there.
var _MANDATORY_PARAMS = {
scenario: { "SCENARIO_NAME": "scenario name", "SCENARIO_DATE": "scenario date" },
}
} ;
// --------------------------------------------------------------------
@ -42,7 +42,7 @@ $(document).ready( function () {
// handle requests to generate HTML snippets
$("input[type='button'].generate").click( function() {
generate_snippet( $(this) )
generate_snippet( $(this) ) ;
} ) ;
} ) ;
@ -53,7 +53,7 @@ function generate_snippet( $btn )
{
// collect all the template parameters
var params = {} ;
add_param = function($elem) { params[ $elem.attr("name").toUpperCase() ] = $elem.val() ; }
add_param = function($elem) { params[ $elem.attr("name").toUpperCase() ] = $elem.val() ; } ;
$("input[type='text'].param").each( function() { add_param($(this)) ; } ) ;
$("textarea.param").each( function() { add_param($(this)) ; } ) ;
@ -79,8 +79,9 @@ function generate_snippet( $btn )
showErrorMsg( "Unknown template: " + escapeHTML(template_id) ) ;
return ;
}
var func, val ;
try {
var func = jinja.compile( gDefaultTemplates[template_id] ).render ;
func = jinja.compile( gDefaultTemplates[template_id] ).render ;
}
catch( ex ) {
showErrorMsg( "Can't compile template:<pre>" + escapeHTML(ex) + "</pre>" ) ;
@ -89,7 +90,7 @@ function generate_snippet( $btn )
// process the template
try {
var val = func( params ) ;
val = func( params ) ;
}
catch( ex ) {
showErrorMsg( "Can't process template <em>\"" + template_id + "\"</em>:<pre>" + escapeHTML(ex) + "</pre>" ) ;

@ -86,9 +86,9 @@
</div>
</body>
<script src="{{url_for('static',filename='jquery-3.3.1.min.js')}}"></script>
<script src="{{url_for('static',filename='jquery/jquery-3.3.1.min.js')}}"></script>
<script src="{{url_for('static',filename='jquery-ui/jquery-ui.min.js')}}"></script>
<script src="{{url_for('static',filename='jinja.js')}}"></script>
<script src="{{url_for('static',filename='jinja/jinja.js')}}"></script>
<script src="{{url_for('static',filename='growl/jquery.growl.js')}}"></script>
<script>
gGetTemplatesUrl = "{{url_for('get_templates')}}" ;

@ -0,0 +1,44 @@
"""Run JSHint over the Javascript files."""
import os.path
import subprocess
import pytest
# ---------------------------------------------------------------------
@pytest.mark.skipif( not os.environ.get("JSHINT_RHINO"), reason="JSHint not configured." )
def test_jshint():
"""Run JSHint over the Javascript files.
To set up JSHint:
- install Rhino (Mozilla's Java-based (!) Javascript):
sudo dnf install rhino
- download and unpack JSHint:
https://github.com/jshint/jshint
- set JSHINT_RHINO to point to $/dist/jshint-rhino.js"
IMPORTANT: Rhino + JSHint has been broken for some time:
https://github.com/jshint/jshint/issues/2308
For now, use JSHint 2.6.3 :-/
"""
# initialize
jshint = os.environ[ "JSHINT_RHINO" ]
# check each Javascript file
dname = os.path.join( os.path.split(__file__)[0], "../static/" )
for fname in os.listdir(dname):
if os.path.splitext(fname)[1] != ".js":
continue
# run JSHint for the next file
proc = subprocess.run(
[ jshint, os.path.join(dname,fname) ],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
)
if proc.stdout or proc.stderr:
print( "=== JSHint failed: {} ===".format( fname ) )
if proc.stdout:
print( proc.stdout )
if proc.stderr:
print( proc.stderr )
assert False
Loading…
Cancel
Save