Add jshint for javascript linting

Added nodeenv as a test requirement.

Added a jshint environment to tox.ini, which installs node.js into the
python virtual environment with nodeenv, installs jshint using npm,
and calls runtest.sh to run the tests.

runtest.sh now supports the -j|--jshint flags to run jshint on the
javascript files. jshint must be installed before running runtest.sh

The documentation also got updated to include some info about testing.

Change-Id: I3e7dcea481806eddc10625fe353ac9092b30573a
Partial-Bug: #1282961
This commit is contained in:
Peter Belanyi 2014-05-22 15:39:32 +02:00
parent 48d6374927
commit 51673a0dfc
4 changed files with 50 additions and 2 deletions

View File

@ -1,5 +1,5 @@
Contributing Contributing
------------ ============
The code repository is located at `OpenStack <https://github.com/openstack>`__. The code repository is located at `OpenStack <https://github.com/openstack>`__.
Please go there if you want to check it out: Please go there if you want to check it out:
@ -24,6 +24,34 @@ If you're interested in the code, here are some key places to start:
* `tuskar_ui/infrastructure <https://github.com/openstack/tuskar-ui/tree/master/tuskar_ui/infrastructure>`_ * `tuskar_ui/infrastructure <https://github.com/openstack/tuskar-ui/tree/master/tuskar_ui/infrastructure>`_
- The Tuskar UI code is contained within this directory. - The Tuskar UI code is contained within this directory.
Running tests
=============
There are several ways to run tests for tuskar-ui.
Using ``tox``:
This is the easiest way to run tests. When run, tox installs dependencies,
prepares the virtual python environment, then runs test commands. The gate
tests in gerrit usually also use tox to run tests. For avaliable tox
environments, see ``tox.ini``.
By running ``run_tests.sh``:
Tests can also be run using the ``run_tests.sh`` script, to see available
options, run it with the ``--help`` option. It handles preparing the
virtual environment and executing tests, but in contrast with tox, it does
not install all dependencies, e.g. ``jshint`` must be installed before
running the jshint testcase.
Manual tests:
To manually check tuskar-ui, it is possible to run a development server
for tuskar-ui by running ``run_tests.sh --runserver``.
To run the server with the settings used by the test environment:
``run_tests.sh --runserver 0.0.0.0:8000 --settings=tuskar_ui.test.settings``
OpenStack Style Commandments OpenStack Style Commandments
============================ ============================

View File

@ -27,6 +27,7 @@ function usage {
echo " -p, --pep8 Just run pep8" echo " -p, --pep8 Just run pep8"
echo " -t, --tabs Check for tab characters in files." echo " -t, --tabs Check for tab characters in files."
echo " -y, --pylint Just run pylint" echo " -y, --pylint Just run pylint"
echo " -j, --jshint Just run jshint"
echo " -q, --quiet Run non-interactively. (Relatively) quiet." echo " -q, --quiet Run non-interactively. (Relatively) quiet."
echo " Implies -V if -N is not set." echo " Implies -V if -N is not set."
echo " --only-selenium Run only the Selenium unit tests" echo " --only-selenium Run only the Selenium unit tests"
@ -63,6 +64,7 @@ just_pep8=0
just_pylint=0 just_pylint=0
just_docs=0 just_docs=0
just_tabs=0 just_tabs=0
just_jshint=0
never_venv=0 never_venv=0
quiet=0 quiet=0
restore_env=0 restore_env=0
@ -94,6 +96,7 @@ function process_option {
-N|--no-virtual-env) always_venv=0; never_venv=1;; -N|--no-virtual-env) always_venv=0; never_venv=1;;
-p|--pep8) just_pep8=1;; -p|--pep8) just_pep8=1;;
-y|--pylint) just_pylint=1;; -y|--pylint) just_pylint=1;;
-j|--jshint) just_jshint=1;;
-f|--force) force=1;; -f|--force) force=1;;
-t|--tabs) just_tabs=1;; -t|--tabs) just_tabs=1;;
-q|--quiet) quiet=1;; -q|--quiet) quiet=1;;
@ -137,6 +140,11 @@ function run_pylint {
fi fi
} }
function run_jshint {
echo "Running jshint ..."
jshint tuskar_ui/infrastructure/static/infrastructure
}
function run_pep8 { function run_pep8 {
echo "Running flake8 ..." echo "Running flake8 ..."
DJANGO_SETTINGS_MODULE=tuskar_ui.test.settings ${command_wrapper} flake8 $included_dirs DJANGO_SETTINGS_MODULE=tuskar_ui.test.settings ${command_wrapper} flake8 $included_dirs
@ -438,6 +446,12 @@ if [ $just_tabs -eq 1 ]; then
exit $? exit $?
fi fi
# Jshint
if [ $just_jshint -eq 1 ]; then
run_jshint
exit $?
fi
# Django development server # Django development server
if [ $runserver -eq 1 ]; then if [ $runserver -eq 1 ]; then
run_server run_server

View File

@ -5,6 +5,7 @@ coverage>=3.6
django-nose django-nose
mock>=1.0 mock>=1.0
mox>=0.5.3 mox>=0.5.3
nodeenv
nose nose
nose-exclude nose-exclude
nosexcover nosexcover

View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py26,py27,py27dj14,py27dj15,py27dj16,pep8 envlist = py26,py27,py27dj14,py27dj15,py27dj16,pep8,selenium,jshint
[testenv] [testenv]
setenv = VIRTUAL_ENV={envdir} setenv = VIRTUAL_ENV={envdir}
@ -39,6 +39,11 @@ commands = pip install django>=1.6,<1.7
[testenv:selenium] [testenv:selenium]
commands = /bin/bash run_tests.sh -N --only-selenium commands = /bin/bash run_tests.sh -N --only-selenium
[testenv:jshint]
commands = nodeenv -p
npm install jshint -g
/bin/bash run_tests.sh -N --jshint
[tox:jenkins] [tox:jenkins]
downloadcache = ~/cache/pip downloadcache = ~/cache/pip