github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/resources/resource_transformers/tocss/dartsass/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 dartsass_test 15 16 import ( 17 "testing" 18 19 "github.com/gohugoio/hugo/hugolib" 20 "github.com/gohugoio/hugo/resources/resource_transformers/tocss/dartsass" 21 ) 22 23 func TestTransformIncludePaths(t *testing.T) { 24 if !dartsass.Supports() { 25 t.Skip() 26 } 27 28 files := ` 29 -- assets/scss/main.scss -- 30 @import "moo"; 31 -- node_modules/foo/_moo.scss -- 32 $moolor: #fff; 33 34 moo { 35 color: $moolor; 36 } 37 -- config.toml -- 38 -- layouts/index.html -- 39 {{ $cssOpts := (dict "includePaths" (slice "node_modules/foo") "transpiler" "dartsass" ) }} 40 {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }} 41 T1: {{ $r.Content }} 42 ` 43 44 b := hugolib.NewIntegrationTestBuilder( 45 hugolib.IntegrationTestConfig{ 46 T: t, 47 TxtarString: files, 48 NeedsOsFS: true, 49 }).Build() 50 51 b.AssertFileContent("public/index.html", `T1: moo{color:#fff}`) 52 } 53 54 func TestTransformImportRegularCSS(t *testing.T) { 55 if !dartsass.Supports() { 56 t.Skip() 57 } 58 59 files := ` 60 -- assets/scss/_moo.scss -- 61 $moolor: #fff; 62 63 moo { 64 color: $moolor; 65 } 66 -- assets/scss/another.css -- 67 68 -- assets/scss/main.scss -- 69 @import "moo"; 70 @import "regular.css"; 71 @import "moo"; 72 @import "another.css"; 73 74 /* foo */ 75 -- assets/scss/regular.css -- 76 77 -- config.toml -- 78 -- layouts/index.html -- 79 {{ $r := resources.Get "scss/main.scss" | toCSS (dict "transpiler" "dartsass") }} 80 T1: {{ $r.Content | safeHTML }} 81 82 ` 83 84 b := hugolib.NewIntegrationTestBuilder( 85 hugolib.IntegrationTestConfig{ 86 T: t, 87 TxtarString: files, 88 NeedsOsFS: true, 89 }, 90 ).Build() 91 92 // Dart Sass does not follow regular CSS import, but they 93 // get pulled to the top. 94 b.AssertFileContent("public/index.html", `T1: @import "regular.css"; 95 @import "another.css"; 96 moo { 97 color: #fff; 98 } 99 100 moo { 101 color: #fff; 102 } 103 104 /* foo */`) 105 } 106 107 func TestTransformThemeOverrides(t *testing.T) { 108 if !dartsass.Supports() { 109 t.Skip() 110 } 111 112 files := ` 113 -- assets/scss/components/_boo.scss -- 114 $boolor: green; 115 116 boo { 117 color: $boolor; 118 } 119 -- assets/scss/components/_moo.scss -- 120 $moolor: #ccc; 121 122 moo { 123 color: $moolor; 124 } 125 -- config.toml -- 126 theme = 'mytheme' 127 -- layouts/index.html -- 128 {{ $cssOpts := (dict "includePaths" (slice "node_modules/foo" ) "transpiler" "dartsass" ) }} 129 {{ $r := resources.Get "scss/main.scss" | toCSS $cssOpts | minify }} 130 T1: {{ $r.Content }} 131 -- themes/mytheme/assets/scss/components/_boo.scss -- 132 $boolor: orange; 133 134 boo { 135 color: $boolor; 136 } 137 -- themes/mytheme/assets/scss/components/_imports.scss -- 138 @import "moo"; 139 @import "_boo"; 140 @import "_zoo"; 141 -- themes/mytheme/assets/scss/components/_moo.scss -- 142 $moolor: #fff; 143 144 moo { 145 color: $moolor; 146 } 147 -- themes/mytheme/assets/scss/components/_zoo.scss -- 148 $zoolor: pink; 149 150 zoo { 151 color: $zoolor; 152 } 153 -- themes/mytheme/assets/scss/main.scss -- 154 @import "components/imports"; 155 ` 156 157 b := hugolib.NewIntegrationTestBuilder( 158 hugolib.IntegrationTestConfig{ 159 T: t, 160 TxtarString: files, 161 NeedsOsFS: true, 162 }, 163 ).Build() 164 165 b.AssertFileContent("public/index.html", `T1: moo{color:#ccc}boo{color:green}zoo{color:pink}`) 166 }