aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/packagemanager/pnpm_test.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:44 +0800
commitdd84b9d64fb98746a230cd24233ff50a562c39c9 (patch)
treeb583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/packagemanager/pnpm_test.go
parent0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff)
downloadHydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz
HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip
Diffstat (limited to 'cli/internal/packagemanager/pnpm_test.go')
-rw-r--r--cli/internal/packagemanager/pnpm_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/cli/internal/packagemanager/pnpm_test.go b/cli/internal/packagemanager/pnpm_test.go
new file mode 100644
index 0000000..c05bc43
--- /dev/null
+++ b/cli/internal/packagemanager/pnpm_test.go
@@ -0,0 +1,57 @@
+package packagemanager
+
+import (
+ "os"
+ "testing"
+
+ "github.com/vercel/turbo/cli/internal/fs"
+ "github.com/vercel/turbo/cli/internal/turbopath"
+ "gotest.tools/v3/assert"
+)
+
+func pnpmPatchesSection(t *testing.T, pkgJSON *fs.PackageJSON) map[string]interface{} {
+ t.Helper()
+ pnpmSection, ok := pkgJSON.RawJSON["pnpm"].(map[string]interface{})
+ assert.Assert(t, ok)
+ patchesSection, ok := pnpmSection["patchedDependencies"].(map[string]interface{})
+ assert.Assert(t, ok)
+ return patchesSection
+}
+
+func getPnpmPackageJSON(t *testing.T) *fs.PackageJSON {
+ t.Helper()
+ rawCwd, err := os.Getwd()
+ assert.NilError(t, err)
+ cwd, err := fs.CheckedToAbsoluteSystemPath(rawCwd)
+ assert.NilError(t, err)
+ pkgJSONPath := cwd.Join("fixtures", "pnpm-patches.json")
+ pkgJSON, err := fs.ReadPackageJSON(pkgJSONPath)
+ assert.NilError(t, err)
+ return pkgJSON
+}
+
+func Test_PnpmPrunePatches_KeepsNecessary(t *testing.T) {
+ pkgJSON := getPnpmPackageJSON(t)
+ initialPatches := pnpmPatchesSection(t, pkgJSON)
+
+ assert.DeepEqual(t, initialPatches, map[string]interface{}{"is-odd@3.0.1": "patches/is-odd@3.0.1.patch"})
+
+ err := pnpmPrunePatches(pkgJSON, []turbopath.AnchoredUnixPath{turbopath.AnchoredUnixPath("patches/is-odd@3.0.1.patch")})
+ assert.NilError(t, err)
+
+ newPatches := pnpmPatchesSection(t, pkgJSON)
+ assert.DeepEqual(t, newPatches, map[string]interface{}{"is-odd@3.0.1": "patches/is-odd@3.0.1.patch"})
+}
+
+func Test_PnpmPrunePatches_RemovesExtra(t *testing.T) {
+ pkgJSON := getPnpmPackageJSON(t)
+ initialPatches := pnpmPatchesSection(t, pkgJSON)
+
+ assert.DeepEqual(t, initialPatches, map[string]interface{}{"is-odd@3.0.1": "patches/is-odd@3.0.1.patch"})
+
+ err := pnpmPrunePatches(pkgJSON, nil)
+ assert.NilError(t, err)
+
+ newPatches := pnpmPatchesSection(t, pkgJSON)
+ assert.DeepEqual(t, newPatches, map[string]interface{}{})
+}