github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/genny/assets/webpack/webpack_test.go (about)

     1  package webpack
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"github.com/gobuffalo/genny/v2"
     8  	"github.com/gobuffalo/genny/v2/gentest"
     9  	"github.com/gobuffalo/meta"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func runner() *genny.Runner {
    14  	run := gentest.NewRunner()
    15  	run.Disk.Add(genny.NewFileS("templates/application.plush.html", layout))
    16  	run.LookPathFn = func(s string) (string, error) {
    17  		return s, nil
    18  	}
    19  	return run
    20  }
    21  
    22  func Test_Webpack_New(t *testing.T) {
    23  	r := require.New(t)
    24  
    25  	g, err := New(&Options{})
    26  	r.NoError(err)
    27  
    28  	run := runner()
    29  
    30  	run.With(g)
    31  	r.NoError(run.Run())
    32  
    33  	res := run.Results()
    34  
    35  	r.Len(res.Commands, 1)
    36  	c := res.Commands[0]
    37  	r.Equal("npm install --no-progress --save", strings.Join(c.Args, " "))
    38  
    39  	files := []string{
    40  		".babelrc",
    41  		"assets/css/_buffalo.scss",
    42  		"assets/css/application.scss",
    43  		"assets/images/favicon.ico",
    44  		"assets/images/logo.svg",
    45  		"assets/js/application.js",
    46  		"package.json",
    47  		"postcss.config.js",
    48  		"public/assets/.keep",
    49  		"templates/application.plush.html",
    50  		"webpack.config.js",
    51  	}
    52  	r.Len(res.Files, len(files))
    53  	for i, f := range res.Files {
    54  		r.Equal(files[i], f.Name())
    55  	}
    56  
    57  	f, err := res.Find("package.json")
    58  	r.NoError(err)
    59  	r.Contains(f.String(), `"bootstrap": "4.`)
    60  
    61  }
    62  
    63  func Test_Webpack_New_WithYarn(t *testing.T) {
    64  	r := require.New(t)
    65  
    66  	g, err := New(&Options{
    67  		App: meta.App{WithYarn: true},
    68  	})
    69  	r.NoError(err)
    70  
    71  	run := runner()
    72  	run.With(g)
    73  	r.NoError(run.Run())
    74  
    75  	res := run.Results()
    76  	r.Len(res.Commands, 1)
    77  	r.Len(res.Files, 11)
    78  
    79  	c := res.Commands[0]
    80  	r.Equal("yarnpkg install --no-progress --save", strings.Join(c.Args, " "))
    81  }
    82  
    83  const layout = `<!DOCTYPE html>
    84  <html>
    85    <head>
    86      <title>Buffalo - Foo</title>
    87      <%= stylesheetTag("buffalo.css") %>
    88      <%= stylesheetTag("application.css") %>
    89    </head>
    90    <body>
    91    </body>
    92  </html>
    93  `