Skip to content

Commit ddee67f

Browse files
committed
Test asset pipeline stylesheet splitting.
1 parent 88c99a9 commit ddee67f

File tree

8 files changed

+60
-0
lines changed

8 files changed

+60
-0
lines changed

test/css_splitter_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,41 @@
11
require 'test_helper'
22

33
class CssSplitterTest < ActiveSupport::TestCase
4+
5+
setup :clear_assets_cache
6+
47
test "truth" do
58
assert_kind_of Module, CssSplitter
69
end
10+
11+
test "asset pipeline stylesheet splitting" do
12+
part1 = "#test{background-color:red}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT
13+
part2 = "#test{background-color:green}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT
14+
part3 = "#test{background-color:blue}"
15+
16+
assert_equal "#{part1}#{part2}#{part3}\n", assets["erb_stylesheet"].to_s
17+
assert_equal "#{part2}\n", assets["erb_stylesheet_split2"].to_s
18+
assert_equal "#{part3}\n", assets["erb_stylesheet_split3"].to_s
19+
end
20+
21+
test "asset pipeline stylesheet splitting on stylesheet combined using requires" do
22+
red = "#test{background-color:red}" * 100
23+
green = "#test{background-color:green}" * CssSplitter::Splitter::MAX_SELECTORS_DEFAULT
24+
blue = "#test{background-color:blue}"
25+
26+
assert_equal "#{red}#{green}#{blue}\n", assets["combined"].to_s
27+
assert_equal "#{"#test{background-color:green}" * 100}#{blue}\n", assets["combined_split2"].to_s
28+
end
29+
30+
private
31+
32+
def clear_assets_cache
33+
assets_cache = Rails.root.join("tmp/cache/assets")
34+
assets_cache.rmtree if assets_cache.exist?
35+
end
36+
37+
def assets
38+
Rails.application.assets
39+
end
40+
741
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//= require 'red_100'
2+
//= require 'green_max'
3+
4+
#test { background-color: blue; }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
*= require 'combined'
3+
*/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %>
2+
#test { background-color: red; }
3+
<% end %>
4+
<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %>
5+
#test { background-color: green; }
6+
<% end %>
7+
#test { background-color: blue; }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
*= require 'erb_stylesheet.css'
3+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/*
2+
*= require 'erb_stylesheet.css'
3+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% CssSplitter::Splitter::MAX_SELECTORS_DEFAULT.times do %>
2+
#test { background-color: green; }
3+
<% end %>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% 100.times do %>
2+
#test { background-color: red; }
3+
<% end %>

0 commit comments

Comments
 (0)