DEV: Split slow test in multiple smaller tests
This might be faster because the smaller chunks of the test may run in parallel.
This commit is contained in:
parent
22c7fde850
commit
768a9d0785
|
@ -859,63 +859,59 @@ RSpec.describe Stylesheet::Manager do
|
|||
%w[desktop mobile admin wizard desktop_rtl mobile_rtl admin_rtl wizard_rtl]
|
||||
end
|
||||
|
||||
before { STDERR.stubs(:write) }
|
||||
let(:theme_targets) { %i[desktop_theme mobile_theme] }
|
||||
|
||||
before do
|
||||
STDERR.stubs(:write)
|
||||
StylesheetCache.destroy_all
|
||||
default_theme.set_default!
|
||||
end
|
||||
|
||||
after do
|
||||
STDERR.unstub(:write)
|
||||
Stylesheet::Manager.rm_cache_folder
|
||||
end
|
||||
|
||||
it "correctly generates precompiled CSS" do
|
||||
scheme1 = ColorScheme.create!(name: "scheme1")
|
||||
scheme2 = ColorScheme.create!(name: "scheme2")
|
||||
theme_targets = %i[desktop_theme mobile_theme]
|
||||
fab!(:scheme1) { ColorScheme.create!(name: "scheme1") }
|
||||
fab!(:scheme2) { ColorScheme.create!(name: "scheme2") }
|
||||
|
||||
Theme.update_all(user_selectable: false)
|
||||
user_theme = Fabricate(:theme, user_selectable: true, color_scheme: scheme1)
|
||||
default_theme = Fabricate(:theme, user_selectable: true, color_scheme: scheme2)
|
||||
fab!(:user_theme) { Fabricate(:theme, user_selectable: true, color_scheme: scheme1) }
|
||||
fab!(:default_theme) { Fabricate(:theme, user_selectable: true, color_scheme: scheme2) }
|
||||
fab!(:child_theme) do
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
end
|
||||
fab!(:child_theme_with_css) do
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
default_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
end
|
||||
|
||||
child_theme =
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
t.save!
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
it "generates precompiled CSS - only core" do
|
||||
capture_output(:stderr) { Stylesheet::Manager.precompile_css }
|
||||
|
||||
child_theme_with_css =
|
||||
Fabricate(:theme).tap do |t|
|
||||
t.component = true
|
||||
expect(StylesheetCache.pluck(:target)).to contain_exactly(*core_targets)
|
||||
end
|
||||
|
||||
t.set_field(target: :common, name: :scss, value: "body { background: green }")
|
||||
|
||||
t.save!
|
||||
|
||||
user_theme.add_relative_theme!(:child, t)
|
||||
default_theme.add_relative_theme!(:child, t)
|
||||
end
|
||||
|
||||
default_theme.set_default!
|
||||
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# only core
|
||||
output = capture_output(:stderr) { Stylesheet::Manager.precompile_css }
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results).to contain_exactly(*core_targets)
|
||||
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# only themes
|
||||
it "generates precompiled CSS - only themes" do
|
||||
output = capture_output(:stderr) { Stylesheet::Manager.precompile_theme_css }
|
||||
|
||||
# Ensure we force compile each theme only once
|
||||
expect(output.scan(/#{child_theme_with_css.name}/).length).to eq(2)
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(22) # (3 themes * 2 targets) + 16 color schemes (2 themes * 8 color schemes (7 defaults + 1 theme scheme))
|
||||
expect(StylesheetCache.count).to eq(22) # (3 themes * 2 targets) + 16 color schemes (2 themes * 8 color schemes (7 defaults + 1 theme scheme))
|
||||
end
|
||||
|
||||
# themes + core
|
||||
it "generates precompiled CSS - core and themes" do
|
||||
Stylesheet::Manager.precompile_css
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(30) # 11 core targets + 9 theme + 10 color schemes
|
||||
|
||||
|
@ -924,13 +920,14 @@ RSpec.describe Stylesheet::Manager do
|
|||
results.count { |target| target =~ /^#{tar}_(#{user_theme.id}|#{default_theme.id})$/ },
|
||||
).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly generates precompiled CSS - core and themes and no default theme" do
|
||||
Theme.clear_default!
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
# themes + core with no theme set as default
|
||||
Stylesheet::Manager.precompile_css
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
results = StylesheetCache.pluck(:target)
|
||||
expect(results.size).to eq(30) # 11 core targets + 9 theme + 10 color schemes
|
||||
|
||||
|
@ -948,33 +945,24 @@ RSpec.describe Stylesheet::Manager do
|
|||
image = file_from_fixtures("logo.png")
|
||||
upload = UploadCreator.new(image, "logo.png").create_for(-1)
|
||||
|
||||
scheme = ColorScheme.create!(name: "scheme")
|
||||
theme_targets = %i[desktop_theme mobile_theme]
|
||||
ThemeField.create!(
|
||||
theme_id: default_theme.id,
|
||||
target_id: Theme.targets[:common],
|
||||
name: "logo",
|
||||
value: "",
|
||||
upload_id: upload.id,
|
||||
type_id: ThemeField.types[:theme_upload_var],
|
||||
)
|
||||
|
||||
default_theme =
|
||||
Fabricate(:theme, color_scheme: scheme).tap do |t|
|
||||
field =
|
||||
ThemeField.create!(
|
||||
theme_id: t.id,
|
||||
target_id: Theme.targets[:common],
|
||||
name: "logo",
|
||||
value: "",
|
||||
upload_id: upload.id,
|
||||
type_id: ThemeField.types[:theme_upload_var],
|
||||
)
|
||||
default_theme.set_field(
|
||||
target: :common,
|
||||
name: :scss,
|
||||
value: "body { background: url($logo); border: 3px solid green; }",
|
||||
)
|
||||
|
||||
t.set_field(
|
||||
target: :common,
|
||||
name: :scss,
|
||||
value: "body { background: url($logo); border: 3px solid green; }",
|
||||
)
|
||||
default_theme.save!
|
||||
|
||||
t.save!
|
||||
end
|
||||
|
||||
default_theme.set_default!
|
||||
upload.destroy!
|
||||
StylesheetCache.destroy_all
|
||||
|
||||
Stylesheet::Manager.precompile_theme_css
|
||||
|
||||
|
|
Loading…
Reference in New Issue