aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/lib/nots/package_manager/pnpm/tests/workspace.py
blob: ffc010de8828fd2a39a8c465f5dac59edcd2686b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from build.plugins.lib.nots.package_manager.base import PackageJson
from build.plugins.lib.nots.package_manager.pnpm.workspace import PnpmWorkspace


def test_workspace_get_paths():
    ws = PnpmWorkspace(path="/packages/foo/pnpm-workspace.yaml")
    ws.packages = set([".", "../bar", "../../another/baz"])

    assert sorted(ws.get_paths()) == [
        "/another/baz",
        "/packages/bar",
        "/packages/foo",
    ]


def test_workspace_get_paths_with_custom_base_path_without_self():
    ws = PnpmWorkspace(path="/packages/foo/pnpm-workspace.yaml")
    ws.packages = set([".", "../bar", "../../another/baz"])

    assert sorted(ws.get_paths(base_path="some/custom/dir", ignore_self=True)) == [
        "some/another/baz",
        "some/custom/bar",
    ]


def test_workspace_set_from_package_json():
    ws = PnpmWorkspace(path="/packages/foo/pnpm-workspace.yaml")
    pj = PackageJson(path="/packages/foo/package.json")
    pj.data = {
        "dependencies": {
            "@a/bar": "workspace:../bar",
        },
        "devDependencies": {
            "@a/baz": "workspace:../../another/baz",
        },
        "peerDependencies": {
            "@a/qux": "workspace:../../another/qux",
        },
        "optionalDependencies": {
            "@a/quux": "workspace:../../another/quux",
        },
    }

    ws.set_from_package_json(pj)

    assert sorted(ws.get_paths()) == [
        "/another/baz",
        "/another/quux",
        "/another/qux",
        "/packages/bar",
        "/packages/foo",
    ]


def test_workspace_merge():
    ws1 = PnpmWorkspace(path="/packages/foo/pnpm-workspace.yaml")
    ws1.packages = set([".", "../bar", "../../another/baz"])
    ws2 = PnpmWorkspace(path="/another/baz/pnpm-workspace.yaml")
    ws2.packages = set([".", "../qux"])

    ws1.merge(ws2)

    assert sorted(ws1.get_paths()) == [
        "/another/baz",
        "/another/qux",
        "/packages/bar",
        "/packages/foo",
    ]