| 1 |
|
| 2 |
|
| 3 |
require_relative "spec_helper" |
| 4 |
|
| 5 |
describe AutoprefixerRails do |
| 6 |
before :all do |
| 7 |
@dir = Pathname(__FILE__).dirname |
| 8 |
@css = @dir.join("app/app/assets/stylesheets/test.css").read |
| 9 |
end |
| 10 |
|
| 11 |
it "process CSS" do |
| 12 |
expect(AutoprefixerRails.process(@css)).to be_a(AutoprefixerRails::Result) |
| 13 |
end |
| 14 |
|
| 15 |
it "process CSS for selected browsers" do |
| 16 |
css = "a {\n tab-size: 2\n}" |
| 17 |
result = AutoprefixerRails.process(css, overrideBrowserslist: ["opera 12"]) |
| 18 |
expect(result.css).to eq "a {\n" \ |
| 19 |
" -o-tab-size: 2;\n" \ |
| 20 |
" tab-size: 2\n" \ |
| 21 |
"}" |
| 22 |
end |
| 23 |
|
| 24 |
it "has browsers option" do |
| 25 |
css = "a {\n tab-size: 2\n}" |
| 26 |
result = AutoprefixerRails.process(css, browsers: ["opera 12"]) |
| 27 |
expect(result.css).to eq "a {\n" \ |
| 28 |
" -o-tab-size: 2;\n" \ |
| 29 |
" tab-size: 2\n" \ |
| 30 |
"}" |
| 31 |
end |
| 32 |
|
| 33 |
it "process @supports" do |
| 34 |
css = "@supports (display: flex) { }" |
| 35 |
result = AutoprefixerRails.process(css, overrideBrowserslist: ["chrome 28"]) |
| 36 |
expect(result.css).to eq( |
| 37 |
"@supports ((display: -webkit-flex) or (display: flex)) { }" |
| 38 |
) |
| 39 |
end |
| 40 |
|
| 41 |
it "generates source map" do |
| 42 |
result = AutoprefixerRails.process(@css, map: true) |
| 43 |
expect(result.css).to include("/*# sourceMappingURL=data:") |
| 44 |
end |
| 45 |
|
| 46 |
it "generates separated source map" do |
| 47 |
result = AutoprefixerRails.process(@css, map: { inline: false }) |
| 48 |
expect(result.map).to be_a(String) |
| 49 |
end |
| 50 |
|
| 51 |
it "uses file name in syntax errors", not_jruby: true do |
| 52 |
expect do |
| 53 |
AutoprefixerRails.process("a {", from: "a.css") |
| 54 |
end.to raise_error(/a.css:/) |
| 55 |
end |
| 56 |
|
| 57 |
it "includes sourcesContent by default" do |
| 58 |
map = AutoprefixerRails.process("a{}", map: { inline: false }).map |
| 59 |
expect(map).to include("sourcesContent") |
| 60 |
end |
| 61 |
|
| 62 |
it "maps options from Ruby style" do |
| 63 |
map = AutoprefixerRails.process("a{}", map: { |
| 64 |
sources_content: false, |
| 65 |
inline: false |
| 66 |
}).map |
| 67 |
|
| 68 |
expect(map).not_to include("sourcesContent") |
| 69 |
end |
| 70 |
|
| 71 |
it "does not remove old prefixes on request" do |
| 72 |
css = "a { -moz-border-radius: 5px; border-radius: 5px }" |
| 73 |
result = AutoprefixerRails.process(css, remove: false) |
| 74 |
expect(result.css).to eq(css) |
| 75 |
end |
| 76 |
|
| 77 |
it "shows debug" do |
| 78 |
info = AutoprefixerRails.processor(overrideBrowserslist: ["chrome 25"]).info |
| 79 |
expect(info).to match(/Browsers:\n Chrome: 25\n\n/) |
| 80 |
expect(info).to match(/ transition: webkit/) |
| 81 |
end |
| 82 |
|
| 83 |
it "returns warnings" do |
| 84 |
css = "a{background:linear-gradient(top,white,black)}" |
| 85 |
result = AutoprefixerRails.process(css) |
| 86 |
expect(result.warnings).to eq(["<css input>:1:3: Gradient has outdated " \ |
| 87 |
"direction syntax. New syntax is like `to left` instead of `right`."]) |
| 88 |
end |
| 89 |
|
| 90 |
it "shows correct error on country statistics" do |
| 91 |
expect do |
| 92 |
AutoprefixerRails.process("", overrideBrowserslist: "> 1% in US") |
| 93 |
end.to raise_error(/Use Autoprefixer with webpack/) |
| 94 |
end |
| 95 |
|
| 96 |
context "Sprockets" do |
| 97 |
before :each do |
| 98 |
@assets = Sprockets::Environment.new |
| 99 |
@assets.append_path(@dir.join("app/app/assets/stylesheets")) |
| 100 |
AutoprefixerRails.install(@assets, overrideBrowserslist: ["chrome 25"]) |
| 101 |
end |
| 102 |
|
| 103 |
it "integrates with Sprockets" do |
| 104 |
css = @assets["test.css"].to_s |
| 105 |
expect(css).to eq "a {\n" \ |
| 106 |
" -webkit-mask: none;\n" \ |
| 107 |
" mask: none\n" \ |
| 108 |
"}\n" |
| 109 |
end |
| 110 |
|
| 111 |
it "shows file name from Sprockets", not_jruby: true do |
| 112 |
expect { @assets["wrong.css"] }.to raise_error(/wrong/) |
| 113 |
end |
| 114 |
|
| 115 |
it "supports disabling", not_jruby: true do |
| 116 |
AutoprefixerRails.uninstall(@assets) |
| 117 |
css = @assets["test.css"].to_s |
| 118 |
expect(css).to eq "a {\n" \ |
| 119 |
" mask: none\n" \ |
| 120 |
"}\n" |
| 121 |
end |
| 122 |
end |
| 123 |
end |