github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/build/assets_test.go (about) 1 package build 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/gobuffalo/envy" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func Test_assets(t *testing.T) { 12 r := require.New(t) 13 14 opts := &Options{ 15 WithAssets: true, 16 } 17 r.NoError(opts.Validate()) 18 opts.App.WithNodeJs = true 19 opts.App.PackageJSON.Scripts = map[string]string{ 20 "build": "webpack -p --progress", 21 } 22 23 run := cokeRunner() 24 run.WithNew(assets(opts)) 25 26 envy.MustSet("NODE_ENV", "") 27 ne := envy.Get("NODE_ENV", "") 28 r.Empty(ne) 29 r.NoError(run.Run()) 30 31 ne = envy.Get("NODE_ENV", "") 32 r.NotEmpty(ne) 33 r.Equal(opts.Environment, ne) 34 35 res := run.Results() 36 37 cmds := []string{"npm run build"} 38 r.Len(res.Commands, len(cmds)) 39 for i, c := range res.Commands { 40 r.Equal(cmds[i], strings.Join(c.Args, " ")) 41 } 42 } 43 44 func Test_assets_Archived(t *testing.T) { 45 r := require.New(t) 46 47 opts := &Options{ 48 WithAssets: true, 49 ExtractAssets: true, 50 } 51 r.NoError(opts.Validate()) 52 53 run := cokeRunner() 54 opts.Root = run.Root 55 run.WithNew(assets(opts)) 56 r.NoError(run.Run()) 57 58 res := run.Results() 59 60 cmds := []string{} 61 r.Len(res.Commands, len(cmds)) 62 for i, c := range res.Commands { 63 r.Equal(cmds[i], strings.Join(c.Args, " ")) 64 } 65 66 // r.Len(res.Files, 1) 67 68 f, err := res.Find("actions/app.go") 69 r.NoError(err) 70 r.Contains(f.String(), `// app.ServeFiles("/"`) 71 }