diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-04-07 08:33:31 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-04-07 16:40:15 +0200 |
commit | 3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673 (patch) | |
tree | c7b80101a86ee29348c72af76d81fcc2af45099b /publisher | |
parent | 8a308944e46f8c2aa054005d5aed89f2711f9c1d (diff) | |
download | hugo-3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673.tar.gz hugo-3d5dbdcb1a11b059fc2f93ed6fadb9009bf72673.zip |
publisher: Also test minified HTML in the element collector
Updates #7567
Diffstat (limited to 'publisher')
-rw-r--r-- | publisher/htmlElementsCollector_test.go | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go index 5a1802234..5b2d85d47 100644 --- a/publisher/htmlElementsCollector_test.go +++ b/publisher/htmlElementsCollector_test.go @@ -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" ) @@ -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 @@ -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) + }) + } } } |