Skip to content

Commit

Permalink
Yarn Berry: simplify yarnrc parsing unit test
Browse files Browse the repository at this point in the history
With the change of the YarnRc class to a UserDict subclass, the test
that covers parsing a valid .yarnrc.yml file can be greatly simplified.

Signed-off-by: Bruno Pimentel <[email protected]>
  • Loading branch information
brunoapimentel committed Jan 8, 2025
1 parent ff8722d commit b4e4c6e
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions tests/unit/package_managers/yarn/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
)
from cachi2.core.rooted_path import PathOutsideRoot, RootedPath

# the supportedArchitectures property is not currently mapped in the YarnRc class, but is kept
# here because it's one of the default properties generated by "yarn init -2"
VALID_YARNRC_FILE = """
cacheFolder: ./.custom/cache
VALID_YARNRC_FILE = """cacheFolder: ./.custom/cache
checksumBehavior: ignore
enableGlobalCache: true
enableImmutableCache: true
Expand All @@ -32,28 +29,29 @@
globalFolder: /a/global/folder
ignorePath: true
installStatePath: /custom/install-state.gz
lockfileFilename: custom.lock
nodeLinker: pnp
npmRegistryServer: https://registry.alternative.com
npmScopes:
foobar:
npmRegistryServer: https://registry.foobar.com
foobar:
npmRegistryServer: https://registry.foobar.com
patchFolder: /custom/patches
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: '@yarnpkg/plugin-typescript'
- path: .yarn/plugins/@yarnpkg/plugin-exec.cjs
spec: '@yarnpkg/plugin-exec'
pnpDataPath: /custom/.pnp.data.json
pnpMode: loose
pnpUnpluggedFolder: /some/unplugged/folder
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-exec.cjs
spec: "@yarnpkg/plugin-exec"
supportedArchitectures:
os:
- "linux"
- linux
unsafeHttpWhitelist:
- example.org
- foo.bar
yarnPath: .custom/path/yarn-3.6.1.cjs
- example.org
- foo.bar
virtualFolder: /custom/__virtual__
yarnPath: .custom/path/yarn-3.6.1.cjs
"""

EMPTY_YML_FILE = ""
Expand Down Expand Up @@ -86,30 +84,7 @@ def _prepare_yarnrc_file(rooted_tmp_path: RootedPath, data: str) -> YarnRc:

def test_parse_yarnrc(rooted_tmp_path: RootedPath) -> None:
yarn_rc = _prepare_yarnrc_file(rooted_tmp_path, VALID_YARNRC_FILE)

assert yarn_rc["cacheFolder"] == "./.custom/cache"
assert yarn_rc["checksumBehavior"] == "ignore"
assert yarn_rc["enableGlobalCache"] is True
assert yarn_rc["enableImmutableCache"] is True
assert yarn_rc["enableImmutableInstalls"] is True
assert yarn_rc["enableMirror"] is False
assert yarn_rc["enableScripts"] is False
assert yarn_rc["enableStrictSsl"] is False
assert yarn_rc["enableTelemetry"] is False
assert yarn_rc["globalFolder"] == "/a/global/folder"
assert yarn_rc["ignorePath"] is True
assert yarn_rc["installStatePath"] == "/custom/install-state.gz"
assert yarn_rc["nodeLinker"] == "pnp"
assert yarn_rc["patchFolder"] == "/custom/patches"
assert yarn_rc["pnpDataPath"] == "/custom/.pnp.data.json"
assert yarn_rc["pnpMode"] == "loose"
assert yarn_rc["pnpUnpluggedFolder"] == "/some/unplugged/folder"
assert yarn_rc["npmRegistryServer"] == "https://registry.alternative.com"
assert yarn_rc.registry_server_for_scope("foobar") == "https://registry.foobar.com"
assert yarn_rc.registry_server_for_scope("barfoo") == "https://registry.alternative.com"
assert yarn_rc["unsafeHttpWhitelist"] == ["example.org", "foo.bar"]
assert yarn_rc["yarnPath"] == ".custom/path/yarn-3.6.1.cjs"
assert yarn_rc["virtualFolder"] == "/custom/__virtual__"
assert yaml.safe_dump(yarn_rc.data) == VALID_YARNRC_FILE


def test_parse_empty_yarnrc(rooted_tmp_path: RootedPath) -> None:
Expand Down

0 comments on commit b4e4c6e

Please sign in to comment.