Skip to content

Commit

Permalink
fix(tests): completed test coverage for npm2
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlday authored and Lee-W committed Aug 26, 2023
1 parent f50e71e commit d36d170
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commitizen/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def set_version(self, version: str):
json.dumps(lock_document, indent=self.indent) + "\n"
)
if self.shrinkwrap_file.exists():
shrinkwrap_document = self.set_lock_version(
shrinkwrap_document = self.set_shrinkwrap_version(
json.loads(self.shrinkwrap_file.read_text()), version
)
self.shrinkwrap_file.write_text(
Expand Down
26 changes: 26 additions & 0 deletions tests/test_version_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,20 @@ def test_scm_provider_default_without_commits_and_tags(config: BaseConfig):
}
"""

NPM_NO_VERSION = """\
{
"name": "whatever"
}
"""

NPM_MULTIPLE_VERSIONS = """\
{
"name": "whatever",
"version": "0.1.0",
"version": "0.2.0",
}
"""

NPM2_PROVIDER = [
(
NPM_PACKAGE_JSON,
Expand Down Expand Up @@ -348,3 +362,15 @@ def test_npm2_provider(
assert pkg_lock.read_text() == dedent(pkg_lock_expected)
if pkg_shrinkwrap_content:
assert pkg_shrinkwrap.read_text() == dedent(pkg_shrinkwrap_expected)


def test_npm2_exceptions(
config: BaseConfig,
):
config.settings["version_provider"] = "npm2"
provider = get_provider(config)
assert isinstance(provider, Npm2Provider)
with pytest.raises(ValueError):
provider.get_package_version(NPM_NO_VERSION)
with pytest.raises(ValueError):
provider.get_package_version(NPM_MULTIPLE_VERSIONS)

0 comments on commit d36d170

Please sign in to comment.