Skip to content

Commit

Permalink
publisher: Also test minified HTML in the element collector
Browse files Browse the repository at this point in the history
Updates #7567
  • Loading branch information
bep committed Apr 7, 2021
1 parent 8a30894 commit 3d5dbdc
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions publisher/htmlElementsCollector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
"strings"
"testing"

"github.com/gohugoio/hugo/minifiers"

"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/output"
"github.com/spf13/viper"

qt "github.com/frankban/quicktest"
)

Expand All @@ -42,6 +48,11 @@ func TestClassCollector(t *testing.T) {
}
}

skipMinifyTest := map[string]bool{
"Script tags content should be skipped": true, // /~https://github.com/tdewolff/minify/issues/396

}

for _, test := range []struct {
name string
html string
Expand Down Expand Up @@ -96,12 +107,25 @@ func TestClassCollector(t *testing.T) {
{"Pre tags content should be skipped", `<pre class="preclass"><span>foo</span><span>bar</span></pre><div class="foo"></div>`, f("div pre", "foo preclass", "")},
{"Textare tags content should be skipped", `<textarea class="textareaclass"><span>foo</span><span>bar</span></textarea><div class="foo"></div>`, f("div textarea", "foo textareaclass", "")},
} {
c.Run(test.name, func(c *qt.C) {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector())
fmt.Fprint(w, test.html)
got := w.collector.getHTMLElements()
c.Assert(got, qt.DeepEquals, test.expect)
})

for _, minify := range []bool{false, true} {
c.Run(fmt.Sprintf("%s--minify-%t", test.name, minify), func(c *qt.C) {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector())

if minify {
if skipMinifyTest[test.name] {
c.Skip("skip minify test")
}
v := viper.New()
m, _ := minifiers.New(media.DefaultTypes, output.DefaultFormats, v)
m.Minify(media.HTMLType, w, strings.NewReader(test.html))
} else {
fmt.Fprint(w, test.html)
}
got := w.collector.getHTMLElements()
c.Assert(got, qt.DeepEquals, test.expect)
})
}
}
}

Expand Down

0 comments on commit 3d5dbdc

Please sign in to comment.