Compare commits

...

1 Commits

Author SHA1 Message Date
Bjørn Erik Pedersen e04f7cd378 js/esbuild: Add an integration test for multiple options for the same input JS file
See #14254
2025-12-12 11:01:55 +01:00
2 changed files with 76 additions and 4 deletions
+32 -4
View File
@@ -438,15 +438,43 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s
func (s *IntegrationTestBuilder) AssertFileContentEquals(filename string, match string) {
s.Helper()
content := s.FileContent(filename)
s.Assert(content, qt.Equals, match, qt.Commentf(match))
var negate bool
match, negate = s.negate(match)
if negate {
s.Assert(content, qt.Not(qt.Equals), match, qt.Commentf(match))
} else {
s.Assert(content, qt.Equals, match, qt.Commentf(match))
}
}
func (s *IntegrationTestBuilder) AssertFileContentExact(filename string, matches ...string) {
s.Helper()
content := s.FileContent(filename)
for _, m := range matches {
cm := qt.Commentf("File: %s Match %s\nContent:\n%s", filename, m, content)
s.Assert(content, qt.Contains, m, cm)
for _, match := range matches {
var negate bool
match, negate = s.negate(match)
cm := qt.Commentf("File: %s Match %s\nContent:\n%s", filename, match, content)
if negate {
s.Assert(content, qt.Not(qt.Contains), match, cm)
} else {
s.Assert(content, qt.Contains, match, cm)
}
}
}
func (s *IntegrationTestBuilder) AssertFileContentRe(filename string, expressions ...string) {
s.Helper()
content := s.FileContent(filename)
for _, e := range expressions {
var negate bool
e, negate = s.negate(e)
re := regexp.MustCompile(e)
cm := qt.Commentf("File: %s Expression %s\nContent:\n%s", filename, e, content)
if negate {
s.Assert(re.MatchString(content), qt.IsFalse, cm)
} else {
s.Assert(re.MatchString(content), qt.IsTrue, cm)
}
}
}
@@ -0,0 +1,44 @@
// Copyright 2025 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package js provides functions for building JavaScript resources
package esbuild_test
import (
"testing"
"github.com/gohugoio/hugo/hugolib"
)
func TestBuilSameJSWithDifferentOptionsIssue14254(t *testing.T) {
files := `
-- hugo.toml --
-- assets/js/app1.js --
import * as params from '@params';
console.log(params);
-- layouts/home.html --
{{ $opts1 := dict "targetPath" "app1_1.js" "minify" true "params" (dict "key" "value1") }}
{{ $opts2 := dict "targetPath" "app1_2.js" "minify" true "params" (dict "key" "value2") }}
{{ $js1 := resources.Get "js/app1.js" | js.Build $opts1 }}
js1: {{ $js1.RelPermalink }}|{{ $js1.Content | safeHTML }}$
{{ $js2 := resources.Get "js/app1.js" | js.Build $opts2 }}
js2: {{ $js2.RelPermalink }}|{{ $js2.Content | safeHTML }}$
`
b := hugolib.Test(t, files)
b.AssertFileContentRe("public/index.html",
`js1.*app1_1.*value1`,
`js2.*app1_2.*value2`,
)
}