aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/resource_transformers
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2022-02-09 14:04:57 +0100
committerBjørn Erik Pedersen <[email protected]>2022-02-09 15:41:32 +0100
commitd22f7795c721272b03f49ee41211adf054931e53 (patch)
tree5eb336efd447969f3d9d03560780f92e468e0f01 /resources/resource_transformers
parent39f69ca7f078fe00ca80eef8f512f894a78e8f68 (diff)
downloadhugo-d22f7795c721272b03f49ee41211adf054931e53.tar.gz
hugo-d22f7795c721272b03f49ee41211adf054931e53.zip
tocss: Port integration tests to their package
Diffstat (limited to 'resources/resource_transformers')
-rw-r--r--resources/resource_transformers/tocss/dartsass/integration_test.go173
-rw-r--r--resources/resource_transformers/tocss/scss/integration_test.go173
2 files changed, 346 insertions, 0 deletions
diff --git a/resources/resource_transformers/tocss/dartsass/integration_test.go b/resources/resource_transformers/tocss/dartsass/integration_test.go
new file mode 100644
index 000000000..c1616f684
--- /dev/null
+++ b/resources/resource_transformers/tocss/dartsass/integration_test.go
@@ -0,0 +1,173 @@
+// Copyright 2021 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 dartsass_test
+
+import (
+ "testing"
+
+ qt "github.com/frankban/quicktest"
+
+ "github.com/gohugoio/hugo/hugolib"
+ "github.com/gohugoio/hugo/resources/resource_transformers/tocss/dartsass"
+)
+
+func TestTransformIncludePaths(t *testing.T) {
+ if !dartsass.Supports() {
+ t.Skip()
+ }
+
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/main.scss --
+@import "moo";
+-- node_modules/foo/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- config.toml --
+-- layouts/index.html --
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") "transpiler" "dartsass" ) }}
+{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
+T1: {{ $r.Content }}
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ }).Build()
+
+ b.AssertFileContent("public/index.html", `T1: moo{color:#fff}`)
+}
+
+func TestTransformImportRegularCSS(t *testing.T) {
+ if !dartsass.Supports() {
+ t.Skip()
+ }
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- assets/scss/another.css --
+
+-- assets/scss/main.scss --
+@import "moo";
+@import "regular.css";
+@import "moo";
+@import "another.css";
+
+/* foo */
+-- assets/scss/regular.css --
+
+-- config.toml --
+-- layouts/index.html --
+{{ $r := resources.Get "scss/main.scss" | toCSS (dict "transpiler" "dartsass") }}
+T1: {{ $r.Content | safeHTML }}
+
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ },
+ ).Build()
+
+ // Dart Sass does not follow regular CSS import, but they
+ // get pulled to the top.
+ b.AssertFileContent("public/index.html", `T1: @import "regular.css";
+ @import "another.css";
+ moo {
+ color: #fff;
+ }
+
+ moo {
+ color: #fff;
+ }
+
+ /* foo */`)
+}
+
+func TestTransformThemeOverrides(t *testing.T) {
+ if !dartsass.Supports() {
+ t.Skip()
+ }
+
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/components/_boo.scss --
+$boolor: green;
+
+boo {
+ color: $boolor;
+}
+-- assets/scss/components/_moo.scss --
+$moolor: #ccc;
+
+moo {
+ color: $moolor;
+}
+-- config.toml --
+theme = 'mytheme'
+-- layouts/index.html --
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) "transpiler" "dartsass" ) }}
+{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
+T1: {{ $r.Content }}
+-- themes/mytheme/assets/scss/components/_boo.scss --
+$boolor: orange;
+
+boo {
+ color: $boolor;
+}
+-- themes/mytheme/assets/scss/components/_imports.scss --
+@import "moo";
+@import "_boo";
+@import "_zoo";
+-- themes/mytheme/assets/scss/components/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- themes/mytheme/assets/scss/components/_zoo.scss --
+$zoolor: pink;
+
+zoo {
+ color: $zoolor;
+}
+-- themes/mytheme/assets/scss/main.scss --
+@import "components/imports";
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", `T1: moo{color:#ccc}boo{color:green}zoo{color:pink}`)
+}
diff --git a/resources/resource_transformers/tocss/scss/integration_test.go b/resources/resource_transformers/tocss/scss/integration_test.go
new file mode 100644
index 000000000..cbc7e192b
--- /dev/null
+++ b/resources/resource_transformers/tocss/scss/integration_test.go
@@ -0,0 +1,173 @@
+// Copyright 2021 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 scss_test
+
+import (
+ "testing"
+
+ qt "github.com/frankban/quicktest"
+
+ "github.com/gohugoio/hugo/hugolib"
+ "github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss"
+)
+
+func TestTransformIncludePaths(t *testing.T) {
+ if !scss.Supports() {
+ t.Skip()
+ }
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/main.scss --
+@import "moo";
+-- node_modules/foo/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- config.toml --
+-- layouts/index.html --
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") ) }}
+{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
+T1: {{ $r.Content }}
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ }).Build()
+
+ b.AssertFileContent("public/index.html", `T1: moo{color:#fff}`)
+}
+
+func TestTransformImportRegularCSS(t *testing.T) {
+ if !scss.Supports() {
+ t.Skip()
+ }
+
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- assets/scss/another.css --
+
+-- assets/scss/main.scss --
+@import "moo";
+@import "regular.css";
+@import "moo";
+@import "another.css";
+
+/* foo */
+-- assets/scss/regular.css --
+
+-- config.toml --
+-- layouts/index.html --
+{{ $r := resources.Get "scss/main.scss" | toCSS }}
+T1: {{ $r.Content | safeHTML }}
+
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ }).Build()
+
+ // LibSass does not support regular CSS imports. There
+ // is an open bug about it that probably will never be resolved.
+ // Hugo works around this by preserving them in place:
+ b.AssertFileContent("public/index.html", `
+ T1: moo {
+ color: #fff; }
+
+@import "regular.css";
+moo {
+ color: #fff; }
+
+@import "another.css";
+/* foo */
+
+`)
+}
+
+func TestTransformThemeOverrides(t *testing.T) {
+ if !scss.Supports() {
+ t.Skip()
+ }
+
+ c := qt.New(t)
+
+ files := `
+-- assets/scss/components/_boo.scss --
+$boolor: green;
+
+boo {
+ color: $boolor;
+}
+-- assets/scss/components/_moo.scss --
+$moolor: #ccc;
+
+moo {
+ color: $moolor;
+}
+-- config.toml --
+theme = 'mytheme'
+-- layouts/index.html --
+{{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) "transpiler" "dartsass" ) }}
+{{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }}
+T1: {{ $r.Content }}
+-- themes/mytheme/assets/scss/components/_boo.scss --
+$boolor: orange;
+
+boo {
+ color: $boolor;
+}
+-- themes/mytheme/assets/scss/components/_imports.scss --
+@import "moo";
+@import "_boo";
+@import "_zoo";
+-- themes/mytheme/assets/scss/components/_moo.scss --
+$moolor: #fff;
+
+moo {
+ color: $moolor;
+}
+-- themes/mytheme/assets/scss/components/_zoo.scss --
+$zoolor: pink;
+
+zoo {
+ color: $zoolor;
+}
+-- themes/mytheme/assets/scss/main.scss --
+@import "components/imports";
+ `
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ TxtarString: files,
+ NeedsOsFS: true,
+ }).Build()
+
+ b.AssertFileContent("public/index.html", `T1: moo{color:#ccc}boo{color:green}zoo{color:pink}`)
+}