From 403966c9455d0cf0a81f3f371af034bb267ddb91 Mon Sep 17 00:00:00 2001 From: Moraxyc Date: Mon, 16 Dec 2024 20:57:30 +0800 Subject: [PATCH] test: add a test for npm lock generation --- tests/test_npm_lock_generate.py | 47 +++++++++++++++++++ tests/testpkgs/default.nix | 1 + tests/testpkgs/npm-lock-generate/default.nix | 23 +++++++++ .../npm-lock-generate/package-lock.json | 0 4 files changed, 71 insertions(+) create mode 100644 tests/test_npm_lock_generate.py create mode 100644 tests/testpkgs/npm-lock-generate/default.nix create mode 100644 tests/testpkgs/npm-lock-generate/package-lock.json diff --git a/tests/test_npm_lock_generate.py b/tests/test_npm_lock_generate.py new file mode 100644 index 0000000..544d00c --- /dev/null +++ b/tests/test_npm_lock_generate.py @@ -0,0 +1,47 @@ +import subprocess + +import conftest + +from nix_update import main + + +def test_update(helpers: conftest.Helpers) -> None: + with helpers.testpkgs(init_git=True) as path: + main( + [ + "--file", + str(path), + "--commit", + "npm-lock-generate", + "--version", + "v2.6.0", + "--generate-lockfile", + ] + ) + npm_deps_name = subprocess.run( + [ + "nix", + "eval", + "--raw", + "--extra-experimental-features", + "nix-command", + "-f", + path, + "npm-lock-generate.npmDeps.name", + ], + check=True, + text=True, + stdout=subprocess.PIPE, + ).stdout.strip() + diff = subprocess.run( + ["git", "-C", path, "show"], + text=True, + stdout=subprocess.PIPE, + check=True, + ).stdout.strip() + print(diff) + assert "2.6.0" in npm_deps_name + assert ( + "https://github.com/olrtg/emmet-language-server/compare/v2.5.0...v2.6.0" + in diff + ) diff --git a/tests/testpkgs/default.nix b/tests/testpkgs/default.nix index 96dd0e5..a1cf273 100644 --- a/tests/testpkgs/default.nix +++ b/tests/testpkgs/default.nix @@ -27,6 +27,7 @@ savanna = pkgs.python3.pkgs.callPackage ./savanna.nix { }; npm = pkgs.callPackage ./npm.nix { }; npm-package = pkgs.callPackage ./npm-package.nix { }; + npm-lock-generate = pkgs.callPackage ./npm-lock-generate { }; pnpm = pkgs.callPackage ./pnpm.nix { }; maven = pkgs.callPackage ./maven.nix { }; mix = pkgs.callPackage ./mix.nix { }; diff --git a/tests/testpkgs/npm-lock-generate/default.nix b/tests/testpkgs/npm-lock-generate/default.nix new file mode 100644 index 0000000..551def1 --- /dev/null +++ b/tests/testpkgs/npm-lock-generate/default.nix @@ -0,0 +1,23 @@ +{ + buildNpmPackage, + fetchFromGitHub, +}: + +buildNpmPackage rec { + pname = "emmet-language-server"; + version = "2.5.0"; + + src = fetchFromGitHub { + owner = "olrtg"; + repo = "emmet-language-server"; + rev = "v${version}"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + }; + + npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + + postPatch = '' + cp ${./package-lock.json} ./package-lock.json + ''; + +} diff --git a/tests/testpkgs/npm-lock-generate/package-lock.json b/tests/testpkgs/npm-lock-generate/package-lock.json new file mode 100644 index 0000000..e69de29