-
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathdefault.nix
More file actions
133 lines (122 loc) · 3.27 KB
/
default.nix
File metadata and controls
133 lines (122 loc) · 3.27 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
# pkgs ? import <nixpkgs> {},
lib ? import <nixpkgs/lib>,
nodejsLockUtils ? import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;},
}: {
# test the path strip function
test_nodejsLockUtils_stripPath_simple = let
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar";
in {
expr = nextPath;
expected = "node_modules/@org/lib";
};
test_nodejsLockUtils_stripPath_root = let
nextPath = nodejsLockUtils.stripPath "node_modules/bar";
in {
expr = nextPath;
# The root
expected = "";
};
test_nodejsLockUtils_stripPath_empty = let
nextPath = nodejsLockUtils.stripPath "";
in {
expr = nextPath;
expected = "";
};
test_nodejsLockUtils_stripPath_complex = let
nextPath = nodejsLockUtils.stripPath "node_modules/@org/lib/node_modules/bar/node_modules/foo";
in {
expr = nextPath;
expected = "node_modules/@org/lib/node_modules/bar";
};
# test the resolve function
test_nodejsLockUtils_findEntry_argparse = let
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
path = nodejsLockUtils.findEntry plock "" "argparse";
in {
expr = path;
expected = "node_modules/argparse";
};
test_nodejsLockUtils_findEntry_notFound = let
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
path = builtins.tryEval (nodejsLockUtils.findEntry plock "" "foo");
in {
expr = path;
expected = {
success = false;
value = false;
};
};
test_nodejsLockUtils_findEntry_deepNested_kitten = let
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
path =
nodejsLockUtils.findEntry plock
"node_modules/@org/nested/node_modules/foo"
"kitten";
in {
expr = path;
expected = "node_modules/@org/nested/node_modules/kitten";
};
test_nodejsLockUtils_findEntry_hoisted = let
plock = builtins.fromJSON (builtins.readFile ./package-lock.json);
path =
nodejsLockUtils.findEntry plock
"node_modules/argparse"
"underscore";
in {
expr = path;
expected = "node_modules/underscore";
};
# test the lock
test_nodejsLockUtils_lockfile_v3 = let
plock = {
name = "foo";
version = "1.0.0";
lockfileVersion = 3;
packages = {};
};
in {
expr = nodejsLockUtils.sanitizeLockfile plock;
expected = plock;
};
test_nodejsLockUtils_lockfile_v2 = let
plock = {
name = "foo";
version = "1.0.0";
lockfileVersion = 2;
packages = {};
dependencies = {};
};
in {
expr = nodejsLockUtils.sanitizeLockfile plock;
expected = plock;
};
test_nodejsLockUtils_lockfile_v1 = let
plock = {
name = "foo";
version = "1.0.0";
lockfileVersion = 1;
dependencies = {};
};
in {
expr = nodejsLockUtils.sanitizeLockfile plock;
expectedError = {
type = "ThrownError";
msg = "This lockfile module only supports lockfileVersion 2 and 3";
};
};
test_nodejsLockUtils_lockfile_missing_lockfileVersion = let
plock = {
name = "foo";
version = "1.0.0";
# lockfileVersion = 3;
packages = {};
};
in {
expr = nodejsLockUtils.sanitizeLockfile plock;
expectedError = {
type = "ThrownError";
msg = "lockfileVersion";
};
};
}