github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/resources/resource_transformers/tocss/scss/integration_test.go (about) 1 // Copyright 2021 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package scss_test 15 16 import ( 17 "testing" 18 19 qt "github.com/frankban/quicktest" 20 21 "github.com/gohugoio/hugo/hugolib" 22 "github.com/gohugoio/hugo/resources/resource_transformers/tocss/scss" 23 ) 24 25 func TestTransformIncludePaths(t *testing.T) { 26 if !scss.Supports() { 27 t.Skip() 28 } 29 c := qt.New(t) 30 31 files := ` 32 -- assets/scss/main.scss -- 33 @import "moo"; 34 -- node_modules/foo/_moo.scss -- 35 $moolor: #fff; 36 37 moo { 38 color: $moolor; 39 } 40 -- config.toml -- 41 -- layouts/index.html -- 42 {{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") ) }} 43 {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }} 44 T1: {{ $r.Content }} 45 ` 46 47 b := hugolib.NewIntegrationTestBuilder( 48 hugolib.IntegrationTestConfig{ 49 T: c, 50 TxtarString: files, 51 NeedsOsFS: true, 52 }).Build() 53 54 b.AssertFileContent("public/index.html", `T1: moo{color:#fff}`) 55 } 56 57 func TestTransformImportRegularCSS(t *testing.T) { 58 if !scss.Supports() { 59 t.Skip() 60 } 61 62 c := qt.New(t) 63 64 files := ` 65 -- assets/scss/_moo.scss -- 66 $moolor: #fff; 67 68 moo { 69 color: $moolor; 70 } 71 -- assets/scss/another.css -- 72 73 -- assets/scss/main.scss -- 74 @import "moo"; 75 @import "regular.css"; 76 @import "moo"; 77 @import "another.css"; 78 79 /* foo */ 80 -- assets/scss/regular.css -- 81 82 -- config.toml -- 83 -- layouts/index.html -- 84 {{ $r := resources.Get "scss/main.scss" | toCSS }} 85 T1: {{ $r.Content | safeHTML }} 86 87 ` 88 89 b := hugolib.NewIntegrationTestBuilder( 90 hugolib.IntegrationTestConfig{ 91 T: c, 92 TxtarString: files, 93 NeedsOsFS: true, 94 }).Build() 95 96 // LibSass does not support regular CSS imports. There 97 // is an open bug about it that probably will never be resolved. 98 // Hugo works around this by preserving them in place: 99 b.AssertFileContent("public/index.html", ` 100 T1: moo { 101 color: #fff; } 102 103 @import "regular.css"; 104 moo { 105 color: #fff; } 106 107 @import "another.css"; 108 /* foo */ 109 110 `) 111 } 112 113 func TestTransformThemeOverrides(t *testing.T) { 114 if !scss.Supports() { 115 t.Skip() 116 } 117 118 c := qt.New(t) 119 120 files := ` 121 -- assets/scss/components/_boo.scss -- 122 $boolor: green; 123 124 boo { 125 color: $boolor; 126 } 127 -- assets/scss/components/_moo.scss -- 128 $moolor: #ccc; 129 130 moo { 131 color: $moolor; 132 } 133 -- config.toml -- 134 theme = 'mytheme' 135 -- layouts/index.html -- 136 {{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) "transpiler" "dartsass" ) }} 137 {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }} 138 T1: {{ $r.Content }} 139 -- themes/mytheme/assets/scss/components/_boo.scss -- 140 $boolor: orange; 141 142 boo { 143 color: $boolor; 144 } 145 -- themes/mytheme/assets/scss/components/_imports.scss -- 146 @import "moo"; 147 @import "_boo"; 148 @import "_zoo"; 149 -- themes/mytheme/assets/scss/components/_moo.scss -- 150 $moolor: #fff; 151 152 moo { 153 color: $moolor; 154 } 155 -- themes/mytheme/assets/scss/components/_zoo.scss -- 156 $zoolor: pink; 157 158 zoo { 159 color: $zoolor; 160 } 161 -- themes/mytheme/assets/scss/main.scss -- 162 @import "components/imports"; 163 ` 164 165 b := hugolib.NewIntegrationTestBuilder( 166 hugolib.IntegrationTestConfig{ 167 T: c, 168 TxtarString: files, 169 NeedsOsFS: true, 170 }).Build() 171 172 b.AssertFileContent("public/index.html", `T1: moo{color:#ccc}boo{color:green}zoo{color:pink}`) 173 }