Skip to content

Commit

Permalink
Merge pull request #1137 from openhealthcare/add-opal-location-to-js-…
Browse files Browse the repository at this point in the history
…test-runner

add opal location to the js test runner
  • Loading branch information
davidmiller committed May 25, 2017
2 parents 37b01d8 + 499d4cc commit 083aeee
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
3 changes: 3 additions & 0 deletions doc/docs/reference/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions opal/core/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions opal/core/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 1 addition & 9 deletions opal/scaffolding/plugin_scaffold/config/karma.conf.js.jinja2
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
1 change: 0 additions & 1 deletion opal/static/js/lib/bower_components/ment.io/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ module.exports = function(config) {

});
};

3 changes: 3 additions & 0 deletions opal/tests/test_core_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
5 changes: 5 additions & 0 deletions opal/tests/test_core_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 083aeee

Please sign in to comment.