Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `runway test` will now return a non-zero exit code if any non-required tests failed
- `static-react` sample uses npm instead of yarn

### 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