diff --git a/CHANGELOG.md b/CHANGELOG.md index b61e62e35..c3619e035 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### 0.8.2 (Minor Release) +#### OPAL_LOCATION is added as a system variable when running js tests +If you run opal test js, your karma config is now run in an environment that has +access to the OPAL_LOCATION variable which points to the opal parent directory. + #### A Data Dictionary In The Extract The Extract zip file has a data dictionary with human readable metadata about each field. diff --git a/doc/docs/reference/testing.md b/doc/docs/reference/testing.md index 8b23758ad..9ef484ac2 100644 --- a/doc/docs/reference/testing.md +++ b/doc/docs/reference/testing.md @@ -50,6 +50,9 @@ module.exports = function(config){ }; ``` +If run from opal test js, we set the path to opal as an env variable called +OPAL_LOCATION + ## Test Coverage The Opal test runner has a `-c` option which runs coverage reports for both Python and Javascript code: diff --git a/opal/core/commandline.py b/opal/core/commandline.py index cf1c5f68c..1e832ec7a 100755 --- a/opal/core/commandline.py +++ b/opal/core/commandline.py @@ -115,6 +115,7 @@ def scaffold(args): def test(args): args.userland_here = USERLAND_HERE + args.opal_location = OPAL.parent test_runner.run_tests(args) return diff --git a/opal/core/test_runner.py b/opal/core/test_runner.py index 3c424c48f..f2a66a674 100644 --- a/opal/core/test_runner.py +++ b/opal/core/test_runner.py @@ -73,6 +73,12 @@ def _run_js_tests(args): """ write("Running Javascript Unit Tests") env = os.environ.copy() + + # used by the karma config file where to find the opal karma defaults + # python3 breaks on ffs if we don't explicitly cast the location + # to a string + env["OPAL_LOCATION"] = str(args.opal_location) + if TRAVIS: karma = './node_modules/karma/bin/karma' else: diff --git a/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 b/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 index b74bfc5f6..11c2c6ccf 100644 --- a/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 +++ b/opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2 @@ -1,13 +1,5 @@ module.exports = function(config){ - var opalPath; - if(process.env.TRAVIS){ - python_version = process.env.TRAVIS_PYTHON_VERSION; - opalPath = '/home/travis/virtualenv/python' + python_version + '/src/opal'; - } - else{ - // this should point to the location of Opal on your machine, it may be in the virtualenv - opalPath = '../../opal'; - } + var opalPath = process.env.OPAL_LOCATION; var karmaDefaults = require(opalPath + '/config/karma_defaults.js'); var baseDir = __dirname + '/..'; var coverageFiles = [ diff --git a/opal/static/js/lib/bower_components/ment.io/karma.conf.js b/opal/static/js/lib/bower_components/ment.io/karma.conf.js index 0ba80720c..083ab66d8 100644 --- a/opal/static/js/lib/bower_components/ment.io/karma.conf.js +++ b/opal/static/js/lib/bower_components/ment.io/karma.conf.js @@ -86,4 +86,3 @@ module.exports = function(config) { }); }; - diff --git a/opal/tests/test_core_commandline.py b/opal/tests/test_core_commandline.py index 17d81c482..c4a1119a0 100644 --- a/opal/tests/test_core_commandline.py +++ b/opal/tests/test_core_commandline.py @@ -157,6 +157,9 @@ def test_test(self): mock_args = MagicMock(name='Mock Args') with patch.object(commandline.test_runner, 'run_tests') as rt: commandline.test(mock_args) + mock_args_call = rt.call_args[0][0] + self.assertTrue(mock_args_call.userland_here.endswith("opal")) + self.assertTrue(mock_args_call.opal_location.endswith("opal")) rt.assert_called_with(mock_args) diff --git a/opal/tests/test_core_test_runner.py b/opal/tests/test_core_test_runner.py index 054a6c52e..874f2dae3 100644 --- a/opal/tests/test_core_test_runner.py +++ b/opal/tests/test_core_test_runner.py @@ -152,6 +152,11 @@ def test_run_tests_travis(self, check_call): ], check_call.call_args[0][0] ) + self.assertIn("OPAL_LOCATION", check_call.call_args[1]["env"]) + + self.assertTrue( + isinstance(check_call.call_args[1]["env"]["OPAL_LOCATION"], str) + ) @patch.object(test_runner.subprocess, 'check_call') @patch.object(test_runner.sys, 'exit')