From 76ea1f18374b6a4b9694abaf5f2a4a8af1375722 Mon Sep 17 00:00:00 2001 From: Michael Krotscheck Date: Wed, 3 Jun 2015 16:16:18 -0700 Subject: [PATCH] Trigger tox from package.json, if necessary. This patch adds several fixes to improve karma test handling. * A postinstall hook was added to package.json, which tests for the existence of .venv. If it is not found, it will invoke tox -e py27 --notest. * Both karma.conf files were taught to automatically detect the directories in which the xstatic dependencies might live, and pick the appropriate directory. postinstall was chosen, because setting up a virtual environment is likely to be useful for more than one type of npm job. Change-Id: I822cb020bd8b2ca8d4f994b9734af5636e4bd144 --- horizon/karma.conf.js | 25 ++++++++++++++++++++++--- openstack_dashboard/karma.conf.js | 25 ++++++++++++++++++++++--- package.json | 1 + 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/horizon/karma.conf.js b/horizon/karma.conf.js index 3f6bc7d44c..8cef1246e9 100644 --- a/horizon/karma.conf.js +++ b/horizon/karma.conf.js @@ -1,7 +1,26 @@ -module.exports = function(config){ +var fs = require('fs'); +var path = require('path'); - // Path to xstatic pkg path. - var xstaticPath = '../../.venv/lib/python2.7/site-packages/xstatic/pkg/'; +module.exports = function(config){ + var xstaticPath; + var base_paths = [ + './.venv', + './.tox/py27' + ] + + for( var i = 0; i < base_paths.length; i++) { + var base_path = path.resolve(base_paths[i]); + + if( fs.existsSync(base_path) ) { + xstaticPath = base_path + '/lib/python2.7/site-packages/xstatic/pkg/'; + break; + } + } + + if( !xstaticPath) { + console.error("xStatic libraries not found, please set up venv"); + process.exit(1); + } config.set({ diff --git a/openstack_dashboard/karma.conf.js b/openstack_dashboard/karma.conf.js index 572575401f..3bdb7e0d0a 100644 --- a/openstack_dashboard/karma.conf.js +++ b/openstack_dashboard/karma.conf.js @@ -1,7 +1,26 @@ -module.exports = function(config){ +var fs = require('fs'); +var path = require('path'); - // Path to xstatic pkg path. - var xstaticPath = '../../.venv/lib/python2.7/site-packages/xstatic/pkg/'; +module.exports = function(config){ + var xstaticPath; + var base_paths = [ + './.venv', + './.tox/py27' + ] + + for( var i = 0; i < base_paths.length; i++) { + var base_path = path.resolve(base_paths[i]); + + if( fs.existsSync(base_path) ) { + xstaticPath = base_path + '/lib/python2.7/site-packages/xstatic/pkg/'; + break; + } + } + + if( !xstaticPath) { + console.error("xStatic libraries not found, please set up venv"); + process.exit(1); + } config.set({ diff --git a/package.json b/package.json index 4c283bfa8a..a431e24586 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "phantomjs": "1.9.17" }, "scripts": { + "postinstall": "if [ ! -d .venv ]; then tox -epy27 --notest; fi", "test": "karma start horizon/karma.conf.js --single-run && karma start openstack_dashboard/karma.conf.js --single-run" }, "dependencies": {}