Skip to content

Commit 8a096ab

Browse files
committed
try testing no-sprockets with a special gemfile
1 parent bb7cb49 commit 8a096ab

16 files changed

+473
-428
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ gemfile:
1616
- gemfiles/rails_4.2_sprockets_4.gemfile
1717
- gemfiles/rails_4.1.gemfile
1818
- gemfiles/rails_5.gemfile
19+
- gemfiles/rails_5_no_sprockets.gemfile
1920
- gemfiles/rails_5_sprockets_4.gemfile
2021

2122
matrix:
@@ -33,6 +34,8 @@ matrix:
3334
gemfile: gemfiles/rails_4.2_sprockets_4.gemfile
3435
- rvm: 2.1
3536
gemfile: gemfiles/rails_5.gemfile
37+
- rvm: 2.1
38+
gemfile: gemfiles/rails_5_no_sprockets.gemfile
3639
- rvm: 2.1
3740
gemfile: gemfiles/rails_5_sprockets_4.gemfile
3841
- rvm: jruby-9.0.1.0

gemfiles/rails_5.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "http://rubygems.org"
44

5-
gem "rails", "~> 5.0.0.beta2"
5+
gem "rails", "~> 5.0.0.rc2"
66
gem "turbolinks", "~> 5.0.0.beta"
77

88
gemspec :path => "../"

gemfiles/rails_5_no_sprockets.gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file was generated by Appraisal
2+
3+
source "http://rubygems.org"
4+
5+
gem "rails", "~> 5.0.0.rc2"
6+
7+
gemspec :path => "../"

gemfiles/rails_5_sprockets_4.gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source "http://rubygems.org"
44

5-
gem "rails", "~> 5.0.0.beta2"
5+
gem "rails", "~> 5.0.0.rc2"
66
gem "sprockets", "~> 4.0.x"
77
gem "turbolinks", "~> 5.0.0.beta"
88

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
var Todo = React.createClass({
2+
render: function() {
3+
return React.createElement("li", null, this.props.todo)
4+
}
5+
})

test/dummy/config/application.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
# require "active_record/railtie"
55
require "action_controller/railtie"
66
require "action_mailer/railtie"
7-
require "sprockets/railtie"
7+
8+
# Test no-sprockets environment by testing the gemfile name
9+
SKIP_SPROCKETS = ENV["BUNDLE_GEMFILE"] =~ /no_sprockets/
10+
if !SKIP_SPROCKETS
11+
require "sprockets/railtie"
12+
end
13+
814
require "rails/test_unit/railtie"
915

1016
# Make sure gems in development group are required, for example, react-rails and turbolinks.
@@ -27,7 +33,8 @@ class Application < Rails::Application
2733
# config.i18n.default_locale = :de
2834
config.react.variant = :production
2935
config.react.addons = false
30-
31-
config.assets.enabled = true
36+
if !SKIP_SPROCKETS
37+
config.assets.enabled = true
38+
end
3239
end
3340
end

test/dummy/config/environments/test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# we need this to reload the jsx transformer when different version is dropped in
1010
config.cache_classes = false
1111
config.reload_plugins = true
12-
config.assets.cache_store = :null_store
12+
if !SKIP_SPROCKETS
13+
config.assets.cache_store = :null_store
14+
end
1315

1416
# Do not eager load code on boot. This avoids loading your whole application
1517
# just for the purpose of running a single test. If you are using a tool that
Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,64 @@
11
require 'test_helper'
22

3-
class JSXTransformerTest < ActionDispatch::IntegrationTest
4-
setup do
5-
reset_transformer
6-
React::JSX.transformer_class = React::JSX::JSXTransformer
7-
manually_expire_asset('JSXTransformer.js')
8-
end
3+
when_sprockets_available do
4+
class JSXTransformerTest < ActionDispatch::IntegrationTest
5+
setup do
6+
reset_transformer
7+
React::JSX.transformer_class = React::JSX::JSXTransformer
8+
manually_expire_asset('JSXTransformer.js')
9+
end
910

10-
teardown do
11-
reset_transformer
12-
manually_expire_asset('JSXTransformer.js')
13-
end
11+
teardown do
12+
reset_transformer
13+
manually_expire_asset('JSXTransformer.js')
14+
end
1415

15-
test 'can use dropped-in version of JSX transformer' do
16-
hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js")
17-
replacing_path = Rails.root.join("vendor/assets/react/JSXTransformer.js")
16+
test 'can use dropped-in version of JSX transformer' do
17+
hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js")
18+
replacing_path = Rails.root.join("vendor/assets/react/JSXTransformer.js")
1819

19-
FileUtils.cp hidden_path, replacing_path
20-
manually_expire_asset('example3.js')
20+
FileUtils.cp hidden_path, replacing_path
21+
manually_expire_asset('example3.js')
2122

22-
get '/assets/example3.js'
23-
FileUtils.rm replacing_path
23+
get '/assets/example3.js'
24+
FileUtils.rm replacing_path
2425

25-
assert_response :success
26-
assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip
27-
end
26+
assert_response :success
27+
assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip
28+
end
2829

29-
test 'accepts harmony: true option' do
30-
React::JSX.transform_options = {harmony: true}
31-
get '/assets/harmony_example.js'
32-
assert_response :success
33-
assert_match(/generateGreeting:\s*function\(\)/, @response.body, "object literal methods")
34-
assert_match(/React.__spread/, @response.body, "spreading props")
35-
assert_match(/Your greeting is: '" \+ insertedGreeting \+ "'/, @response.body, "string interpolation")
36-
assert_match(/active=\$__0\.active/, @response.body, "destructuring assignment")
37-
end
30+
test 'accepts harmony: true option' do
31+
React::JSX.transform_options = {harmony: true}
32+
get '/assets/harmony_example.js'
33+
assert_response :success
34+
assert_match(/generateGreeting:\s*function\(\)/, @response.body, "object literal methods")
35+
assert_match(/React.__spread/, @response.body, "spreading props")
36+
assert_match(/Your greeting is: '" \+ insertedGreeting \+ "'/, @response.body, "string interpolation")
37+
assert_match(/active=\$__0\.active/, @response.body, "destructuring assignment")
38+
end
3839

39-
test 'accepts strip_types: true option' do
40-
React::JSX.transform_options = {strip_types: true, harmony: true}
41-
get '/assets/flow_types_example.js'
42-
assert_response :success
43-
assert_match(/\(i\s*,\s*name\s*\)\s*\{/, @response.body, "type annotations are removed")
44-
end
40+
test 'accepts strip_types: true option' do
41+
React::JSX.transform_options = {strip_types: true, harmony: true}
42+
get '/assets/flow_types_example.js'
43+
assert_response :success
44+
assert_match(/\(i\s*,\s*name\s*\)\s*\{/, @response.body, "type annotations are removed")
45+
end
4546

46-
test 'accepts asset_path: option' do
47-
hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js")
48-
custom_path = Rails.root.join("vendor/assets/react/custom")
49-
replacing_path = custom_path.join("CustomTransformer.js")
47+
test 'accepts asset_path: option' do
48+
hidden_path = Rails.root.join("vendor/assets/react/JSXTransformer__.js")
49+
custom_path = Rails.root.join("vendor/assets/react/custom")
50+
replacing_path = custom_path.join("CustomTransformer.js")
5051

51-
React::JSX.transform_options = {asset_path: "custom/CustomTransformer.js"}
52+
React::JSX.transform_options = {asset_path: "custom/CustomTransformer.js"}
5253

53-
FileUtils.mkdir_p(custom_path)
54-
FileUtils.cp(hidden_path, replacing_path)
55-
manually_expire_asset('example3.js')
56-
get '/assets/example3.js'
54+
FileUtils.mkdir_p(custom_path)
55+
FileUtils.cp(hidden_path, replacing_path)
56+
manually_expire_asset('example3.js')
57+
get '/assets/example3.js'
5758

58-
FileUtils.rm_rf custom_path
59-
assert_response :success
60-
assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip
59+
FileUtils.rm_rf custom_path
60+
assert_response :success
61+
assert_equal 'test_confirmation_token_jsx_transformed;', @response.body.strip
62+
end
6163
end
62-
6364
end

test/react/jsx_test.rb

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,54 @@ def transform(code)
2626
end
2727
end
2828

29-
class JSXTransformTest < ActionDispatch::IntegrationTest
30-
setup do
31-
reset_transformer
32-
end
29+
when_sprockets_available do
30+
class JSXTransformTest < ActionDispatch::IntegrationTest
31+
setup do
32+
reset_transformer
33+
end
3334

34-
teardown do
35-
reset_transformer
36-
end
35+
teardown do
36+
reset_transformer
37+
end
3738

38-
test 'asset pipeline should transform JSX' do
39-
manually_expire_asset('example.js')
40-
get '/assets/example.js'
41-
assert_response :success
42-
assert_compiled_javascript_matches(EXPECTED_JS, @response.body)
43-
end
39+
test 'asset pipeline should transform JSX' do
40+
manually_expire_asset('example.js')
41+
get '/assets/example.js'
42+
assert_response :success
43+
assert_compiled_javascript_matches(EXPECTED_JS, @response.body)
44+
end
4445

45-
test 'asset pipeline should transform JSX + Coffeescript' do
46-
manually_expire_asset('example2.js')
47-
get '/assets/example2.js'
48-
assert_response :success
49-
assert_compiled_javascript_matches(EXPECTED_JS_2, @response.body)
50-
end
46+
test 'asset pipeline should transform JSX + Coffeescript' do
47+
manually_expire_asset('example2.js')
48+
get '/assets/example2.js'
49+
assert_response :success
50+
assert_compiled_javascript_matches(EXPECTED_JS_2, @response.body)
51+
end
5152

52-
test 'use a custom transformer' do
53-
React::JSX.transformer_class = NullTransformer
54-
manually_expire_asset('example2.js')
55-
get '/assets/example2.js'
53+
test 'use a custom transformer' do
54+
React::JSX.transformer_class = NullTransformer
55+
manually_expire_asset('example2.js')
56+
get '/assets/example2.js'
5657

57-
assert_equal "TRANSFORMED CODE!;\n", @response.body
58-
end
58+
assert_equal "TRANSFORMED CODE!;\n", @response.body
59+
end
5960

60-
def test_babel_transformer_accepts_babel_transformation_options
61-
React::JSX.transform_options = {blacklist: ['spec.functionName', 'validation.react', "strict"]}
62-
manually_expire_asset('example.js')
63-
get '/assets/example.js'
64-
assert_response :success
61+
def test_babel_transformer_accepts_babel_transformation_options
62+
React::JSX.transform_options = {blacklist: ['spec.functionName', 'validation.react', "strict"]}
63+
manually_expire_asset('example.js')
64+
get '/assets/example.js'
65+
assert_response :success
6566

66-
assert !@response.body.include?('strict')
67-
end
67+
assert !@response.body.include?('strict')
68+
end
6869

6970

70-
# Different processors may generate slightly different outputs,
71-
# as some version inserts an extra "\n" at the beginning.
72-
# Because appraisal is used, multiple versions of coffee-script are treated
73-
# together. Remove all spaces to make test pass.
74-
def assert_compiled_javascript_matches(javascript, expectation)
75-
assert_equal expectation.gsub(/\s/, ''), javascript.gsub(/\s/, '')
71+
# Different processors may generate slightly different outputs,
72+
# as some version inserts an extra "\n" at the beginning.
73+
# Because appraisal is used, multiple versions of coffee-script are treated
74+
# together. Remove all spaces to make test pass.
75+
def assert_compiled_javascript_matches(javascript, expectation)
76+
assert_equal expectation.gsub(/\s/, ''), javascript.gsub(/\s/, '')
77+
end
7678
end
7779
end

0 commit comments

Comments
 (0)