summaryrefslogtreecommitdiffstats
path: root/hugolib/resource_chain_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-25 21:40:02 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-04-07 21:59:20 +0200
commit2f721f8ec69c52202815cd1b543ca4bf535c0901 (patch)
treecae7d1ee9ce867a4bffc70e94513f09e2aebe162 /hugolib/resource_chain_test.go
parent8568928aa8e82a6bd7de4555c3703d8835fbd25b (diff)
Add basic "post resource publish support"
Fixes #7146
Diffstat (limited to 'hugolib/resource_chain_test.go')
-rw-r--r--hugolib/resource_chain_test.go78
1 files changed, 77 insertions, 1 deletions
diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go
index 8bca6c7b5..0d0c9203a 100644
--- a/hugolib/resource_chain_test.go
+++ b/hugolib/resource_chain_test.go
@@ -14,13 +14,16 @@
package hugolib
import (
+ "fmt"
"io"
+ "math/rand"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
+ "time"
"github.com/gohugoio/hugo/common/herrors"
@@ -352,6 +355,80 @@ Edited content.
}
}
+func TestResourceChainPostProcess(t *testing.T) {
+ t.Parallel()
+
+ rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
+
+ b := newTestSitesBuilder(t)
+ b.WithContent("page1.md", "---\ntitle: Page1\n---")
+ b.WithContent("page2.md", "---\ntitle: Page2\n---")
+
+ b.WithTemplates(
+ "_default/single.html", `{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | minify | fingerprint "md5" | resources.PostProcess }}
+HELLO: {{ $hello.RelPermalink }}
+`,
+ "index.html", `Start.
+{{ $hello := "<h1> Hello World! </h1>" | resources.FromString "hello.html" | minify | fingerprint "md5" | resources.PostProcess }}
+
+HELLO: {{ $hello.RelPermalink }}|Integrity: {{ $hello.Data.Integrity }}|MediaType: {{ $hello.MediaType.Type }}
+HELLO2: Name: {{ $hello.Name }}|Content: {{ $hello.Content }}|Title: {{ $hello.Title }}|ResourceType: {{ $hello.ResourceType }}
+
+`+strings.Repeat("a b", rnd.Intn(10)+1)+`
+
+
+End.`)
+
+ b.Running()
+ b.Build(BuildCfg{})
+ b.AssertFileContent("public/index.html",
+ `Start.
+HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html|Integrity: md5-otHLJPJLMip9rVIEFMUj6Q==|MediaType: text/html
+HELLO2: Name: hello.html|Content: <h1>Hello World!</h1>|Title: hello.html|ResourceType: html
+End.`)
+
+ b.AssertFileContent("public/page1/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`)
+ b.AssertFileContent("public/page2/index.html", `HELLO: /hello.min.a2d1cb24f24b322a7dad520414c523e9.html`)
+
+}
+
+func BenchmarkResourceChainPostProcess(b *testing.B) {
+
+ for i := 0; i < b.N; i++ {
+ b.StopTimer()
+ s := newTestSitesBuilder(b)
+ for i := 0; i < 300; i++ {
+ s.WithContent(fmt.Sprintf("page%d.md", i+1), "---\ntitle: Page\n---")
+ }
+ s.WithTemplates("_default/single.html", `Start.
+Some text.
+
+
+{{ $hello1 := "<h1> Hello World 2! </h1>" | resources.FromString "hello.html" | minify | fingerprint "md5" | resources.PostProcess }}
+{{ $hello2 := "<h1> Hello World 2! </h1>" | resources.FromString (printf "%s.html" .Path) | minify | fingerprint "md5" | resources.PostProcess }}
+
+Some more text.
+
+HELLO: {{ $hello1.RelPermalink }}|Integrity: {{ $hello1.Data.Integrity }}|MediaType: {{ $hello1.MediaType.Type }}
+
+Some more text.
+
+HELLO2: Name: {{ $hello2.Name }}|Content: {{ $hello2.Content }}|Title: {{ $hello2.Title }}|ResourceType: {{ $hello2.ResourceType }}
+
+Some more text.
+
+HELLO2_2: Name: {{ $hello2.Name }}|Content: {{ $hello2.Content }}|Title: {{ $hello2.Title }}|ResourceType: {{ $hello2.ResourceType }}
+
+End.
+`)
+
+ b.StartTimer()
+ s.Build(BuildCfg{})
+
+ }
+
+}
+
func TestResourceChains(t *testing.T) {
t.Parallel()
@@ -769,7 +846,6 @@ func TestResourceChainPostCSS(t *testing.T) {
}
if runtime.GOOS == "windows" {
- // TODO(bep)
t.Skip("skip npm test on Windows")
}