summary refs log tree commit diff
path: root/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
diff options
context:
space:
mode:
authorWinter <winter@winter.cafe>2022-11-13 22:14:46 -0500
committerWinter <winter@winter.cafe>2022-11-21 15:00:08 -0500
commit009a234bdd91d91008e95c7e8b9de16439114635 (patch)
treed8b43d7f24fde7aae2fdf7ccb51b18dec8600530 /pkgs/build-support/node/fetch-npm-deps/src/tests.rs
parent091d039b12a485bd3b677d862da5b35da4b19f36 (diff)
prefetch-npm-deps: repack hosted git deps
Previously, we stored the tarballs from the hosted Git providers directly in the cache. However, as we've seen with `fetchFromGitHub` etc, these files may change subtly.

Given this, this commit repacks the dependencies before storing them in the cache.
Diffstat (limited to 'pkgs/build-support/node/fetch-npm-deps/src/tests.rs')
-rw-r--r--pkgs/build-support/node/fetch-npm-deps/src/tests.rs55
1 files changed, 53 insertions, 2 deletions
diff --git a/pkgs/build-support/node/fetch-npm-deps/src/tests.rs b/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
index 99e091cbc2c2e..a3317207c42e4 100644
--- a/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
+++ b/pkgs/build-support/node/fetch-npm-deps/src/tests.rs
@@ -1,7 +1,8 @@
 use super::{
-    get_hosted_git_url, get_ideal_hash, get_initial_url, to_new_packages, OldPackage, Package,
-    UrlOrString,
+    fixup_lockfile, get_hosted_git_url, get_ideal_hash, get_initial_url, to_new_packages,
+    OldPackage, Package, UrlOrString,
 };
+use serde_json::json;
 use std::collections::HashMap;
 use url::Url;
 
@@ -88,3 +89,53 @@ fn git_shorthand_v1() -> anyhow::Result<()> {
 
     Ok(())
 }
+
+#[test]
+fn lockfile_fixup() -> anyhow::Result<()> {
+    let input = json!({
+        "lockfileVersion": 2,
+        "name": "foo",
+        "packages": {
+            "": {
+
+            },
+            "foo": {
+                "resolved": "https://github.com/NixOS/nixpkgs",
+                "integrity": "aaa"
+            },
+            "bar": {
+                "resolved": "git+ssh://git@github.com/NixOS/nixpkgs.git",
+                "integrity": "bbb"
+            }
+        }
+    });
+
+    let expected = json!({
+        "lockfileVersion": 2,
+        "name": "foo",
+        "packages": {
+            "": {
+
+            },
+            "foo": {
+                "resolved": "https://github.com/NixOS/nixpkgs",
+                "integrity": "aaa"
+            },
+            "bar": {
+                "resolved": "git+ssh://git@github.com/NixOS/nixpkgs.git",
+            }
+        }
+    });
+
+    assert_eq!(
+        fixup_lockfile(input.as_object().unwrap().clone())?,
+        Some(expected.as_object().unwrap().clone())
+    );
+
+    assert_eq!(
+        fixup_lockfile(json!({"lockfileVersion": 1}).as_object().unwrap().clone())?,
+        None
+    );
+
+    Ok(())
+}