1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
|
# frozen_string_literal: true
module SharedSassTestNoFunction
extend Sprockets::TestDefinition
test "aren't included globally" do
silence_warnings do
assert sass_functions.instance_methods.include?(:javascript_path)
assert sass_functions.instance_methods.include?(:stylesheet_path)
filename = fixture_path('sass/paths.scss')
assert data = File.read(filename)
engine = sass_engine.new(data, {
filename: filename,
syntax: :scss
})
assert sass_functions.instance_methods.include?(:javascript_path)
assert sass_functions.instance_methods.include?(:stylesheet_path)
assert_equal <<-EOS, engine.render
div {
url: url(asset-path("foo.svg"));
url: url(image-path("foo.png"));
url: url(video-path("foo.mov"));
url: url(audio-path("foo.mp3"));
url: url(font-path("foo.woff2"));
url: url(font-path("foo.woff"));
url: url("/js/foo.js");
url: url("/css/foo.css"); }
EOS
end
end
end
module SharedSassTestSprockets
extend Sprockets::TestDefinition
test "process variables" do
assert_equal <<-EOS, render('sass/variables.sass')
.content-navigation {
border-color: #3bbfce;
color: #2ca2af; }
.border {
padding: 8px;
margin: 8px;
border-color: #3bbfce; }
EOS
end
test "process nesting" do
assert_equal <<-EOS, render('sass/nesting.scss')
table.hl {
margin: 2em 0; }
table.hl td.ln {
text-align: right; }
li {
font-family: serif;
font-weight: bold;
font-size: 1.2em; }
EOS
end
test "@import scss partial from scss" do
assert_equal <<-EOS, render('sass/import_partial.scss')
#navbar li {
border-top-radius: 10px;
-moz-border-radius-top: 10px;
-webkit-border-top-radius: 10px; }
#footer {
border-top-radius: 5px;
-moz-border-radius-top: 5px;
-webkit-border-top-radius: 5px; }
#sidebar {
border-left-radius: 8px;
-moz-border-radius-left: 8px;
-webkit-border-left-radius: 8px; }
EOS
end
test "@import scss partial from sass" do
assert_equal <<-EOS, render('sass/import_partial.sass')
#navbar li {
border-top-radius: 10px;
-moz-border-radius-top: 10px;
-webkit-border-top-radius: 10px; }
#footer {
border-top-radius: 5px;
-moz-border-radius-top: 5px;
-webkit-border-top-radius: 5px; }
#sidebar {
border-left-radius: 8px;
-moz-border-radius-left: 8px;
-webkit-border-left-radius: 8px; }
EOS
end
test "@import sass non-partial from scss" do
assert_equal <<-EOS, render('sass/import_nonpartial.scss')
.content-navigation {
border-color: #3bbfce;
color: #2ca2af; }
.border {
padding: 8px;
margin: 8px;
border-color: #3bbfce; }
EOS
end
test "@import css file from load path" do
skip "Does not work on jruby" if RUBY_PLATFORM.include?('java')
skip "Does not work on windows with sassc" if File::ALT_SEPARATOR && self.sass == ::SassC
assert_match(/\A\s*\z/, render('sass/import_load_path.scss'))
end
test "process css file" do
assert_equal <<-EOS, render('sass/reset.css')
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block; }
EOS
end
test "@import relative file" do
assert_equal <<-EOS, render('sass/shared/relative.scss')
#navbar li {
border-top-radius: 10px;
-moz-border-radius-top: 10px;
-webkit-border-top-radius: 10px; }
#footer {
border-top-radius: 5px;
-moz-border-radius-top: 5px;
-webkit-border-top-radius: 5px; }
#sidebar {
border-left-radius: 8px;
-moz-border-radius-left: 8px;
-webkit-border-left-radius: 8px; }
EOS
end
test "@import relative nested file" do
assert_equal <<-EOS, render('sass/relative.scss')
body {
background: #666666; }
EOS
end
test "modify file causes it to recompile" do
filename = fixture_path('sass/test.scss')
sandbox filename do
File.open(filename, 'w') { |f| f.write "body { background: red; };" }
assert_equal "body {\n background: red; }\n", render(filename)
File.open(filename, 'w') { |f| f.write "body { background: blue; };" }
mtime = Time.now + 1
File.utime(mtime, mtime, filename)
assert_equal "body {\n background: blue; }\n", render(filename)
end
end
test "modify partial causes it to recompile" do
filename, partial = fixture_path('sass/test.scss'), fixture_path('sass/_partial.scss')
sandbox filename, partial do
File.open(filename, 'w') { |f| f.write "@import 'partial';" }
File.open(partial, 'w') { |f| f.write "body { background: red; };" }
assert_equal "body {\n background: red; }\n", render(filename)
File.open(partial, 'w') { |f| f.write "body { background: blue; };" }
mtime = Time.now + 1
File.utime(mtime, mtime, partial)
assert_equal "body {\n background: blue; }\n", render(filename)
end
end
test "reference @import'd variable" do
assert_equal <<-EOS, render('sass/links.scss')
a:link {
color: "red"; }
EOS
end
test "@import reference variable" do
assert_equal <<-EOS, render('sass/main.scss')
#header {
color: "blue"; }
EOS
end
end
module SharedSassTestCompressor
extend Sprockets::TestDefinition
def setup
@env = Sprockets::Environment.new
@env.append_path File.expand_path("../fixtures", __FILE__)
end
test "compress css" do
silence_warnings do
uncompressed = "p {\n margin: 0;\n padding: 0;\n}\n"
compressed = "p{margin:0;padding:0}\n"
input = {
environment: @env,
filename: File.expand_path("../fixtures/uncompressed.css", __FILE__),
load_path: File.expand_path("../fixtures", __FILE__),
data: uncompressed,
metadata: {},
cache: Sprockets::Cache.new
}
assert_equal compressed, compressor.call(input)[:data]
end
end
end
module SharedSassTestFunctions
extend Sprockets::TestDefinition
test "path functions" do
assert_equal <<-EOS, render('sass/paths.scss')
div {
url: url("/foo.svg");
url: url("/foo.png");
url: url("/foo.mov");
url: url("/foo.mp3");
url: url("/foo.woff2");
url: url("/foo.woff");
url: url("/foo.js");
url: url("/foo.css"); }
EOS
end
test "url functions" do
assert_equal <<-EOS, render('sass/urls.scss')
div {
url: url(/foo.svg);
url: url(/foo.png);
url: url(/foo.mov);
url: url(/foo.mp3);
url: url(/foo.woff2);
url: url(/foo.woff);
url: url(/foo.js);
url: url(/foo.css); }
EOS
end
test "url functions with query and hash parameters" do
assert_equal <<-EOS, render('octicons/octicons.scss')
@font-face {
font-family: 'octicons';
src: url(/octicons.eot?#iefix) format("embedded-opentype"), url(/octicons.woff2) format("woff2"), url(/octicons.woff) format("woff"), url(/octicons.ttf) format("truetype"), url(/octicons.svg#octicons) format("svg");
font-weight: normal;
font-style: normal; }
EOS
end
test "path function generates links" do
asset = silence_warnings do
@env.find_asset('sass/paths.css')
end
assert asset
assert_equal [
"file://#{fixture_path_for_uri('compass/foo.css')}?type=text/css&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.js')}?type=application/javascript&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.mov')}?id=xxx",
"file://#{fixture_path_for_uri('compass/foo.mp3')}?type=audio/mpeg&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.svg')}?type=image/png&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.svg')}?type=image/svg+xml&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.woff2')}?type=application/font-woff2&id=xxx",
"file://#{fixture_path_for_uri('compass/foo.woff')}?type=application/font-woff&id=xxx"
], asset.links.to_a.map { |uri| uri.sub(/id=\w+/, 'id=xxx') }.sort
end
test "data-url function" do
assert_equal <<-EOS, render('sass/data_url.scss')
div {
url: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAABlBMVEUFO2sAAADPfNHpAAAACklEQVQIW2NgAAAAAgABYkBPaAAAAABJRU5ErkJggg%3D%3D); }
EOS
end
end
|