diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-03-10 18:12:11 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-03-11 14:13:03 +0100 |
commit | df298558a5a5b747288d9656402af85e0ac75a43 (patch) | |
tree | ed62ce971aeead7cf1833a8e9310dd69cbaa565f /hugolib/resource_chain_test.go | |
parent | b1106f8715cac3544b8ea662b969336fe56fa047 (diff) |
Improve Tailwind/PostCSS error messages
Fixes #7041
Fixes #7042
Diffstat (limited to 'hugolib/resource_chain_test.go')
-rw-r--r-- | hugolib/resource_chain_test.go | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index d3d93b1af..3b5150deb 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -22,6 +22,8 @@ import ( "strings" "testing" + "github.com/gohugoio/hugo/common/herrors" + "github.com/gohugoio/hugo/htesting" "github.com/spf13/viper" @@ -717,11 +719,10 @@ func TestResourceChainPostCSS(t *testing.T) { packageJSON := `{ "scripts": {}, - "dependencies": { - "tailwindcss": "^1.2" - }, + "devDependencies": { - "postcss-cli": "^7.1.0" + "postcss-cli": "^7.1.0", + "tailwindcss": "^1.2" } } ` @@ -826,7 +827,7 @@ Styles Content: Len: 770878| assertCss(b) - build := func(s string, shouldFail bool) { + build := func(s string, shouldFail bool) error { b.Assert(os.RemoveAll(filepath.Join(workDir, "public")), qt.IsNil) v := viper.New() @@ -837,19 +838,37 @@ Styles Content: Len: 770878| b = newTestBuilder(v) b.Assert(os.RemoveAll(filepath.Join(workDir, "public")), qt.IsNil) - b.Assert(os.RemoveAll(filepath.Join(workDir, "node_modules")), qt.IsNil) + err := b.BuildE(BuildCfg{}) if shouldFail { - b.BuildFail(BuildCfg{}) + b.Assert(err, qt.Not(qt.IsNil)) } else { - b.Build(BuildCfg{}) + b.Assert(err, qt.IsNil) assertCss(b) } + + return err } build("always", false) build("fallback", false) + // Introduce a syntax error in an import + b.WithSourceFile("assets/css/components/b.css", `@import "a.css"; + +class-in-b { + @apply asdf; +} +`) + + err = build("newer", true) + + err = herrors.UnwrapErrorWithFileContext(err) + fe, ok := err.(*herrors.ErrorWithFileContext) + b.Assert(ok, qt.Equals, true) + b.Assert(fe.Position().LineNumber, qt.Equals, 4) + b.Assert(fe.Error(), qt.Contains, filepath.Join(workDir, "assets/css/components/b.css:4:1")) + // Remove PostCSS b.Assert(os.RemoveAll(filepath.Join(workDir, "node_modules")), qt.IsNil) |