github.com/JarrahG/buffalocli@v0.0.0-20230801092127-b85bfd5d395a/internal/genny/fix/webpack_test.go (about) 1 package fix 2 3 import ( 4 "testing" 5 6 "github.com/gobuffalo/genny/v2" 7 "github.com/gobuffalo/genny/v2/gentest" 8 "github.com/gobuffalo/meta" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func Test_WebpackCheck_NoOverwriteExisting(t *testing.T) { 13 r := require.New(t) 14 15 opts := &Options{ 16 App: meta.App{ 17 Root: ".", 18 WithWebpack: true, 19 }, 20 } 21 22 run := gentest.NewRunner() 23 bb, err := defaultWebpack(opts.App) 24 r.NoError(err) 25 fileContents := bb.String() 26 r.NoError(run.File(genny.NewFileS("webpack.config.js", fileContents))) 27 28 run.WithRun(WebpackCheck(opts)) 29 r.NoError(run.Run()) 30 31 results := run.Results() 32 f := results.Files[0] 33 r.Equal("webpack.config.js", f.Name()) 34 r.Equal(fileContents, f.String()) 35 } 36 37 func Test_WebpackCheck_UpdatingFile(t *testing.T) { 38 r := require.New(t) 39 40 opts := &Options{ 41 App: meta.App{ 42 Root: ".", 43 WithWebpack: true, 44 }, 45 YesToAll: true, 46 } 47 48 bb, err := defaultWebpack(opts.App) 49 r.NoError(err) 50 fileContents := bb.String() 51 52 run := gentest.NewRunner() 53 r.NoError(run.File(genny.NewFileS("webpack.config.js", "console.log('hello world')"))) 54 55 run.WithRun(WebpackCheck(opts)) 56 r.NoError(run.Run()) 57 58 results := run.Results() 59 60 f := results.Files[0] 61 r.Equal("webpack.config.js", f.Name()) 62 r.Equal(fileContents, f.String()) 63 }