diff options
Diffstat (limited to 'hugolib/hugo_modules_test.go')
-rw-r--r-- | hugolib/hugo_modules_test.go | 159 |
1 files changed, 157 insertions, 2 deletions
diff --git a/hugolib/hugo_modules_test.go b/hugolib/hugo_modules_test.go index 0ed4fceb0..c3358a0c2 100644 --- a/hugolib/hugo_modules_test.go +++ b/hugolib/hugo_modules_test.go @@ -22,6 +22,8 @@ import ( "testing" "time" + "github.com/gohugoio/hugo/modules/npm" + "github.com/gohugoio/hugo/common/loggers" "github.com/spf13/afero" @@ -38,7 +40,6 @@ import ( "github.com/spf13/viper" ) -// https://github.com/gohugoio/hugo/issues/6730 func TestHugoModulesVariants(t *testing.T) { if !isCI() { t.Skip("skip (relative) long running modules test when running locally") @@ -60,8 +61,10 @@ path="github.com/gohugoio/hugoTestModule2" newTestBuilder := func(t testing.TB, moduleOpts string) (*sitesBuilder, func()) { b := newTestSitesBuilder(t) - workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants") + tempDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants") b.Assert(err, qt.IsNil) + workingDir := filepath.Join(tempDir, "myhugosite") + b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil) b.Fs = hugofs.NewDefault(viper.New()) b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts)) b.WithTemplates( @@ -129,6 +132,158 @@ JS imported in module: | `) }) + t.Run("Create package.json", func(t *testing.T) { + + b, clean := newTestBuilder(t, "") + defer clean() + + b.WithSourceFile("package.json", `{ + "name": "mypack", + "version": "1.2.3", + "scripts": {}, + "dependencies": { + "nonon": "error" + } +}`) + + b.WithSourceFile("package.hugo.json", `{ + "name": "mypack", + "version": "1.2.3", + "scripts": {}, + "dependencies": { + "foo": "1.2.3" + }, + "devDependencies": { + "postcss-cli": "7.8.0", + "tailwindcss": "1.8.0" + + } +}`) + + b.Build(BuildCfg{}) + b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil) + + b.AssertFileContentFn("package.json", func(s string) bool { + return s == `{ + "comments": { + "dependencies": { + "foo": "project", + "react-dom": "github.com/gohugoio/hugoTestModule2" + }, + "devDependencies": { + "@babel/cli": "github.com/gohugoio/hugoTestModule2", + "@babel/core": "github.com/gohugoio/hugoTestModule2", + "@babel/preset-env": "github.com/gohugoio/hugoTestModule2", + "postcss-cli": "project", + "tailwindcss": "project" + } + }, + "dependencies": { + "foo": "1.2.3", + "react-dom": "^16.13.1" + }, + "devDependencies": { + "@babel/cli": "7.8.4", + "@babel/core": "7.9.0", + "@babel/preset-env": "7.9.5", + "postcss-cli": "7.8.0", + "tailwindcss": "1.8.0" + }, + "name": "mypack", + "scripts": {}, + "version": "1.2.3" +}` + }) + }) + + t.Run("Create package.json, no default", func(t *testing.T) { + + b, clean := newTestBuilder(t, "") + defer clean() + + b.WithSourceFile("package.json", `{ + "name": "mypack", + "version": "1.2.3", + "scripts": {}, + "dependencies": { + "moo": "1.2.3" + } +}`) + + b.Build(BuildCfg{}) + b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil) + + b.AssertFileContentFn("package.json", func(s string) bool { + return s == `{ + "comments": { + "dependencies": { + "moo": "project", + "react-dom": "github.com/gohugoio/hugoTestModule2" + }, + "devDependencies": { + "@babel/cli": "github.com/gohugoio/hugoTestModule2", + "@babel/core": "github.com/gohugoio/hugoTestModule2", + "@babel/preset-env": "github.com/gohugoio/hugoTestModule2", + "postcss-cli": "github.com/gohugoio/hugoTestModule2", + "tailwindcss": "github.com/gohugoio/hugoTestModule2" + } + }, + "dependencies": { + "moo": "1.2.3", + "react-dom": "^16.13.1" + }, + "devDependencies": { + "@babel/cli": "7.8.4", + "@babel/core": "7.9.0", + "@babel/preset-env": "7.9.5", + "postcss-cli": "7.1.0", + "tailwindcss": "1.2.0" + }, + "name": "mypack", + "scripts": {}, + "version": "1.2.3" +}` + }) + }) + + t.Run("Create package.json, no default, no package.json", func(t *testing.T) { + + b, clean := newTestBuilder(t, "") + defer clean() + + b.Build(BuildCfg{}) + b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil) + + b.AssertFileContentFn("package.json", func(s string) bool { + return s == `{ + "comments": { + "dependencies": { + "react-dom": "github.com/gohugoio/hugoTestModule2" + }, + "devDependencies": { + "@babel/cli": "github.com/gohugoio/hugoTestModule2", + "@babel/core": "github.com/gohugoio/hugoTestModule2", + "@babel/preset-env": "github.com/gohugoio/hugoTestModule2", + "postcss-cli": "github.com/gohugoio/hugoTestModule2", + "tailwindcss": "github.com/gohugoio/hugoTestModule2" + } + }, + "dependencies": { + "react-dom": "^16.13.1" + }, + "devDependencies": { + "@babel/cli": "7.8.4", + "@babel/core": "7.9.0", + "@babel/preset-env": "7.9.5", + "postcss-cli": "7.1.0", + "tailwindcss": "1.2.0" + }, + "name": "myhugosite", + "version": "0.1.0" +}` + }) + }) + } // TODO(bep) this fails when testmodBuilder is also building ... |