Skip to content

Commit

Permalink
the friendly error when npm can't be found has returned (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
ITProKyle authored Jun 1, 2020
1 parent 7c3fd03 commit d3fbc2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed
- issue where `yamllint` and `cfnlint` could not be imported/executed from the Pyinstaller executables

### Fixed
- the friendly error when npm can't be found has returned

## [1.8.0] - 2020-05-16
### Fixed
- the value of `environments` is once again used to determine if a serverless module should be skipped
Expand Down
2 changes: 1 addition & 1 deletion runway/module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def __init__(self, context, path, options=None):
definition.
"""
self.check_for_npm() # fail fast
options = options or {}
super(RunwayModuleNpm, self).__init__(context, path, options)
del self.options # remove the attr set by the parent class
Expand All @@ -178,6 +177,7 @@ def __init__(self, context, path, options=None):
for k, v in options.items():
setattr(self, k, v)

self.check_for_npm() # fail fast
warn_on_boto_env_vars(self.context.env_vars)

def check_for_npm(self):
Expand Down
22 changes: 17 additions & 5 deletions tests/module/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,24 @@ def test_check_for_npm(self, mock_which, caplog, runway_context):
'please ensure it is installed correctly.'] == \
caplog.messages

@patch.object(RunwayModuleNpm, 'check_for_npm', MagicMock(return_value=None))
@patch('runway.module.which')
@patch('runway.module.warn_on_boto_env_vars')
def test_init(self, mock_warn, runway_context, tmp_path):
def test_init(self, mock_warn, mock_which, caplog, runway_context, tmp_path):
"""Test init and the attributes set in init."""
# pylint: disable=no-member
caplog.set_level(logging.ERROR, logger='runway')
mock_which.side_effect = [True, True, False]
options = {
'environments': True, # can only be True of a falsy value (but not dict)
'options': {'test_option': 'option_value'},
'parameters': {'test_parameter': 'parameter_value'},
'extra': 'something'
}
obj = RunwayModuleNpm(context=runway_context,
obj = RunwayModuleNpm(context=runway_context, # side_effect[0]
path=str(tmp_path),
options=options.copy())

obj.check_for_npm.assert_called_once()
mock_which.assert_called_once()
assert obj.context == runway_context
assert obj.environments == options['environments']
assert obj.extra == options['extra']
Expand All @@ -67,13 +69,23 @@ def test_init(self, mock_warn, runway_context, tmp_path):
assert str(obj.path) == str(tmp_path)
mock_warn.assert_called_once_with(runway_context.env_vars)

obj = RunwayModuleNpm(context=runway_context,
obj = RunwayModuleNpm(context=runway_context, # side_effect[1]
path=tmp_path)
assert not obj.environments
assert not obj.options
assert not obj.parameters
assert obj.path == tmp_path

caplog.clear()
with pytest.raises(SystemExit) as excinfo:
obj = RunwayModuleNpm(context=runway_context, # side_effect[2]
path=tmp_path)
assert excinfo.value.code > 0 # non-zero exit code
assert caplog.messages == [
'{}: "npm" not found in path or is not executable; '
'please ensure it is installed correctly.'.format(tmp_path.name)
]

@patch('runway.module.format_npm_command_for_logging')
def test_log_npm_command(self, mock_log, caplog, patch_module_npm,
runway_context):
Expand Down

0 comments on commit d3fbc2d

Please sign in to comment.