diff options
| author | 2023-04-28 01:36:44 +0800 | |
|---|---|---|
| committer | 2023-04-28 01:36:44 +0800 | |
| commit | dd84b9d64fb98746a230cd24233ff50a562c39c9 (patch) | |
| tree | b583261ef00b3afe72ec4d6dacb31e57779a6faf /cli/internal/inference/inference_test.go | |
| parent | 0b46fcd72ac34382387b2bcf9095233efbcc52f4 (diff) | |
| download | HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.tar.gz HydroRoll-dd84b9d64fb98746a230cd24233ff50a562c39c9.zip | |
Diffstat (limited to 'cli/internal/inference/inference_test.go')
| -rw-r--r-- | cli/internal/inference/inference_test.go | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/cli/internal/inference/inference_test.go b/cli/internal/inference/inference_test.go new file mode 100644 index 0000000..ed82ecc --- /dev/null +++ b/cli/internal/inference/inference_test.go @@ -0,0 +1,97 @@ +package inference + +import ( + "reflect" + "testing" + + "github.com/vercel/turbo/cli/internal/fs" +) + +func getFrameworkBySlug(slug string) *Framework { + for _, framework := range _frameworks { + if framework.Slug == slug { + return &framework + } + } + panic("that framework doesn't exist") +} + +func TestInferFramework(t *testing.T) { + tests := []struct { + name string + pkg *fs.PackageJSON + want *Framework + }{ + { + name: "Hello world", + pkg: nil, + want: nil, + }, + { + name: "Empty dependencies", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{}}, + want: nil, + }, + { + name: "Finds Blitz", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "blitz": "*", + }}, + want: getFrameworkBySlug("blitzjs"), + }, + { + name: "Order is preserved (returns blitz, not next)", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "blitz": "*", + "next": "*", + }}, + want: getFrameworkBySlug("blitzjs"), + }, + { + name: "Finds next without blitz", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "next": "*", + }}, + want: getFrameworkBySlug("nextjs"), + }, + { + name: "match strategy of all works (solid)", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "solid-js": "*", + "solid-start": "*", + }}, + want: getFrameworkBySlug("solidstart"), + }, + { + name: "match strategy of some works (nuxt)", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "nuxt3": "*", + }}, + want: getFrameworkBySlug("nuxtjs"), + }, + { + name: "match strategy of some works (c-r-a)", + pkg: &fs.PackageJSON{UnresolvedExternalDeps: map[string]string{ + "react-scripts": "*", + }}, + want: getFrameworkBySlug("create-react-app"), + }, + { + name: "Finds next in non monorepo", + pkg: &fs.PackageJSON{ + Dependencies: map[string]string{ + "next": "*", + }, + Workspaces: []string{}, + }, + want: getFrameworkBySlug("nextjs"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := InferFramework(tt.pkg); !reflect.DeepEqual(got, tt.want) { + t.Errorf("InferFramework() = %v, want %v", got, tt.want) + } + }) + } +} |
