Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
malomalo committed Dec 6, 2023
1 parent ddd9edf commit 45b287a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,34 @@
name: CI

on:
push:
pull_request:
types: [opened]

jobs:
sunstone:
name: Condenser/Rails Test
runs-on: ubuntu-22.04
strategy:
matrix:
rails-version:
- 6.1.7
- 7.0.8
- 7.1.2
ruby-version:
- 3.0
- 3.1
- 3.2

steps:
- uses: actions/checkout@v4

- run: |
echo 'gem "rails", "${{ matrix.rails-version }}"' >> Gemfile
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- run: bundle exec rake test
3 changes: 2 additions & 1 deletion lib/condenser/railtie.rb
Expand Up @@ -60,6 +60,7 @@ def pipeline(&block)

config.assets = OrderedOptions.new
config.assets._blocks = []
config.assets._pipeline = nil
config.assets.path = []
config.assets.precompile = %w(application.css application.js **/*.jpg **/*.png **/*.gif)
config.assets.prefix = "/assets"
Expand Down Expand Up @@ -122,7 +123,7 @@ def build_environment(app, initialized = nil)
config = app.config

if config.assets._pipeline

config.assets._pipeline.call(env)
else
env.register_transformer 'text/scss', 'text/css', Condenser::ScssTransformer.new

Expand Down
43 changes: 43 additions & 0 deletions test/railtie_test.rb
Expand Up @@ -336,6 +336,49 @@ def test_direct_build_environment_call
assert_includes env.path, @rails_root.join("stylesheets").to_s
end

def test_defining_an_empty_pipeline
FileUtils.mkdir_p(File.join(@rails_root, "javascripts"))
FileUtils.mkdir_p(File.join(@rails_root, "stylesheets"))

app.configure do
config.assets.pipeline do |condenser|
end
end
app.initialize!

assert env = app.assets
assert_equal env.templates, {"application/erb"=>Condenser::Erubi, "application/ejs"=>Condenser::EjsTemplate}
assert_equal env.preprocessors, {}
assert_equal env.transformers, {"text/scss"=>{"text/css"=>Condenser::ScssTransformer}, "application/jst"=>{"application/javascript"=>Condenser::JstTransformer}, "image/svg+xml"=>{"application/javascript"=>Condenser::SVGTransformer}}
assert_equal env.postprocessors, {}
assert_equal env.minifiers, {}
assert_equal env.exporters, {}
end

def test_defining_a_pipeline
FileUtils.mkdir_p(File.join(@rails_root, "javascripts"))
FileUtils.mkdir_p(File.join(@rails_root, "stylesheets"))

app.configure do
config.assets.pipeline do |condenser|
condenser.register_preprocessor('application/javascript', Condenser::JSAnalyzer)
condenser.register_postprocessor('text/css', ::Condenser::CSSMediaCombinerProcessor)
condenser.register_minifier('application/javascript', Condenser::TerserMinifier)
condenser.register_writer Condenser::ZlibWriter.new
end
end
app.initialize!

assert env = app.assets
assert_equal env.templates, {"application/erb"=>Condenser::Erubi, "application/ejs"=>Condenser::EjsTemplate}
assert_equal env.preprocessors, {"application/javascript"=>[Condenser::JSAnalyzer]}
assert_equal env.transformers, {"text/scss"=>{"text/css"=>Condenser::ScssTransformer}, "application/jst"=>{"application/javascript"=>Condenser::JstTransformer}, "image/svg+xml"=>{"application/javascript"=>Condenser::SVGTransformer}}
assert_equal env.postprocessors, {"text/css"=>[Condenser::CSSMediaCombinerProcessor]}
assert_equal env.minifiers, {"application/javascript"=>Condenser::TerserMinifier}
assert_equal env.exporters, {}
end


# def test_quiet_assets_defaults_to_off
# app.initialize!
# app.load_tasks
Expand Down

0 comments on commit 45b287a

Please sign in to comment.