core/providers/node/cleanse_test.go
core/providers/node/cleanse_test.goBrowse 1970 files
503 tokens
1,761 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package node2 3import (4 "reflect"5 "testing"6 7 "github.com/railwayapp/railpack/core/plan"8)9 10func buildPlan(withCache bool) *plan.BuildPlan {11 p := plan.NewBuildPlan()12 if withCache {13 p.Caches["node_modules"] = &plan.Cache{Directory: NODE_MODULES_CACHE, Type: plan.CacheTypeShared}14 }15 return p16}17 18func TestCleanse_CachePresent_StepDoesNotRemoveNodeModules(t *testing.T) {19 p := buildPlan(true)20 step := plan.Step{Name: "build", Caches: []string{"node_modules"}}21 step.Commands = []plan.Command{plan.NewExecShellCommand("echo 'nothing to see'")}22 p.Steps = append(p.Steps, step)23 24 provider := &NodeProvider{}25 provider.CleansePlan(p)26 27 if !reflect.DeepEqual(p.Steps[0].Caches, []string{"node_modules"}) {28 t.Fatalf("expected cache to remain since step doesn't remove node_modules, got %#v", p.Steps[0].Caches)29 }30}31 32func TestCleanse_CachePresent_StepRemovesNodeModules(t *testing.T) {33 p := buildPlan(true)34 step := plan.Step{Name: "build", Caches: []string{"node_modules"}}35 step.Commands = []plan.Command{plan.NewExecShellCommand("rm -rf node_modules && echo done")}36 p.Steps = append(p.Steps, step)37 38 provider := &NodeProvider{}39 provider.CleansePlan(p)40 41 if len(p.Steps[0].Caches) != 0 {42 t.Fatalf("expected cache to be removed (nil or empty), got %#v", p.Steps[0].Caches)43 }44}45 46func TestCleanse_InstallStepAlwaysKeepsCache(t *testing.T) {47 p := buildPlan(true)48 install := plan.Step{Name: "install", Caches: []string{"node_modules"}}49 install.Commands = []plan.Command{plan.NewExecShellCommand("npm ci")}50 p.Steps = append(p.Steps, install)51 52 provider := &NodeProvider{}53 provider.CleansePlan(p)54 55 if !reflect.DeepEqual(p.Steps[0].Caches, []string{"node_modules"}) {56 t.Fatalf("expected install step cache to remain, got %#v", p.Steps[0].Caches)57 }58}59