-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yarn: make _configure_yarn_version return a semver.Version
This makes it possible to avoid parsing the version from package.json a second time when setting the .yarnrc.yaml configuration (there's a configuration key that is dependent on the Yarn version). Signed-off-by: Bruno Pimentel <[email protected]>
- Loading branch information
1 parent
07a2353
commit 6e3e77f
Showing
2 changed files
with
21 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
fetch_yarn_source, | ||
) | ||
from cachi2.core.package_managers.yarn.project import PackageJson, Plugin, YarnRc | ||
from cachi2.core.package_managers.yarn.utils import VersionsRange | ||
from cachi2.core.rooted_path import RootedPath | ||
|
||
|
||
|
@@ -271,9 +272,9 @@ def test_resolve_zero_installs_fail() -> None: | |
|
||
|
||
@pytest.mark.parametrize( | ||
"yarn_rc_content, expected_plugins", | ||
"yarn_rc_content, expected_plugins, yarn_version", | ||
[ | ||
pytest.param("", [], id="empty_yarn_rc"), | ||
pytest.param("", [], "3.0.0", id="empty_yarn_rc"), | ||
pytest.param( | ||
SAMPLE_PLUGINS, | ||
[ | ||
|
@@ -282,17 +283,19 @@ def test_resolve_zero_installs_fail() -> None: | |
"spec": "@yarnpkg/plugin-exec", | ||
}, | ||
], | ||
"3.0.0", | ||
id="yarn_rc_with_default_plugins", | ||
), | ||
pytest.param("", [], "4.0.0", id="yarn_v4"), | ||
pytest.param("", [], "4.0.0-rc1", id="yarn_v4_rc1"), | ||
], | ||
) | ||
@mock.patch("cachi2.core.package_managers.yarn.project.YarnRc.write") | ||
@mock.patch("cachi2.core.package_managers.yarn.main.get_semver_from_package_manager") | ||
def test_set_yarnrc_configuration( | ||
mock_get_semver: mock.Mock, | ||
mock_write: mock.Mock, | ||
yarn_rc_content: str, | ||
expected_plugins: list[Plugin], | ||
yarn_version: semver.Version, | ||
rooted_tmp_path: RootedPath, | ||
) -> None: | ||
yarn_rc_path = rooted_tmp_path.join_within_root(".yarnrc.yml") | ||
|
@@ -305,7 +308,7 @@ def test_set_yarnrc_configuration( | |
project.package_json = mock.MagicMock() | ||
output_dir = RootedPath("/tmp/output") | ||
|
||
_set_yarnrc_configuration(project, output_dir) | ||
_set_yarnrc_configuration(project, output_dir, yarn_version) | ||
|
||
expected_data = { | ||
"cacheFolder": "./.yarn/cache", | ||
|
@@ -325,39 +328,13 @@ def test_set_yarnrc_configuration( | |
"plugins": expected_plugins, | ||
} | ||
|
||
if yarn_version in VersionsRange("4.0.0-rc1", "5.0.0"): | ||
expected_data["enableConstraintsChecks"] = False | ||
|
||
assert yarn_rc.data == expected_data | ||
mock_write.assert_called_once() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"yarn_version, enable_constraints_checks", | ||
[ | ||
pytest.param("[email protected]", False, id="yarn-v4"), | ||
pytest.param("[email protected]", False, id="yarn-v4-rc1"), | ||
pytest.param("[email protected]", True, id="yarn-v3"), | ||
], | ||
) | ||
@mock.patch("cachi2.core.package_managers.yarn.project.YarnRc.write") | ||
def test_enable_constraints_checks_in_yarn_v4( | ||
mock_write: mock.Mock, | ||
rooted_tmp_path: RootedPath, | ||
yarn_version: str, | ||
enable_constraints_checks: bool, | ||
) -> None: | ||
yarn_rc = YarnRc(mock.Mock(), {}) | ||
package_json = PackageJson(mock.Mock(), {}) | ||
package_json["packageManager"] = yarn_version | ||
|
||
project = mock.Mock() | ||
project.yarn_rc = yarn_rc | ||
project.package_json = package_json | ||
|
||
_set_yarnrc_configuration(project, rooted_tmp_path) | ||
|
||
# for versions <4, enableConstraintsChecks should not be set | ||
assert yarn_rc.data.get("enableConstraintsChecks", True) is enable_constraints_checks | ||
|
||
|
||
@mock.patch("cachi2.core.package_managers.yarn.main.get_semver_from_package_manager") | ||
def test_verify_yarnrc_paths(mock_get_semver: mock.Mock) -> None: | ||
output_dir = RootedPath("/tmp/output") | ||
|
@@ -366,7 +343,7 @@ def test_verify_yarnrc_paths(mock_get_semver: mock.Mock) -> None: | |
project.yarn_rc = yarn_rc | ||
project.package_json = mock.MagicMock() | ||
|
||
_set_yarnrc_configuration(project, output_dir) | ||
_set_yarnrc_configuration(project, output_dir, semver.Version.parse("3.0.0")) | ||
_verify_yarnrc_paths(project) | ||
|
||
|
||
|