2023-09-05 16:17:49 +03:00
|
|
|
{
|
|
|
|
# pkgs ? import <nixpkgs> {},
|
|
|
|
lib ? import <nixpkgs/lib>,
|
2023-11-05 05:51:34 +03:00
|
|
|
nodejsLockUtils ? import ../../../lib/internal/nodejsLockUtils.nix {inherit lib;},
|
2023-09-05 16:17:49 +03:00
|
|
|
}: {
|
|
|
|
# test the path strip function
|
2024-08-01 18:40:22 +03:00
|
|
|
test_nodejsLockUtils_parentPath_simple = {
|
|
|
|
expr = nodejsLockUtils.parentPath "node_modules/@org/lib/node_modules/bar";
|
2023-09-05 16:17:49 +03:00
|
|
|
expected = "node_modules/@org/lib";
|
|
|
|
};
|
|
|
|
|
2024-08-01 18:40:22 +03:00
|
|
|
test_nodejsLockUtils_parentPath_root = {
|
|
|
|
expr = nodejsLockUtils.parentPath "node_modules/bar";
|
2023-09-05 16:17:49 +03:00
|
|
|
# The root
|
|
|
|
expected = "";
|
|
|
|
};
|
|
|
|
|
2024-08-01 18:40:22 +03:00
|
|
|
test_nodejsLockUtils_parentPath_empty = {
|
|
|
|
expr = nodejsLockUtils.parentPath "";
|
2023-09-05 16:17:49 +03:00
|
|
|
expected = "";
|
|
|
|
};
|
|
|
|
|
2024-08-01 18:40:22 +03:00
|
|
|
test_nodejsLockUtils_parentPath_complex = {
|
|
|
|
expr = nodejsLockUtils.parentPath "node_modules/@org/lib/node_modules/bar/node_modules/foo";
|
2023-09-05 16:17:49 +03:00
|
|
|
expected = "node_modules/@org/lib/node_modules/bar";
|
|
|
|
};
|
|
|
|
|
2024-08-01 18:40:22 +03:00
|
|
|
test_nodejsLockUtils_parentPath_local_package = {
|
|
|
|
expr = nodejsLockUtils.parentPath "packages/foo";
|
|
|
|
expected = "";
|
|
|
|
};
|
|
|
|
|
2023-09-05 16:17:49 +03:00
|
|
|
# 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";
|
|
|
|
};
|
|
|
|
}
|