33
44# Sprockets is inserting a newline after the docblock for some reason...
55EXPECTED_JS = <<eos
6+ "use strict";
7+
68React.createElement("div", null);
79eos
810
911EXPECTED_JS_2 = <<eos
12+ "use strict";
13+
1014(function() {
1115 var Component;
1216
@@ -30,18 +34,19 @@ def transform(code)
3034class JSXTransformTest < ActionDispatch ::IntegrationTest
3135 setup do
3236 clear_sprockets_cache
37+ React ::JSX . transformer_class = React ::JSX ::BabelTransformer
38+ React ::JSX . transform_options = { }
3339 end
3440
3541 teardown do
3642 clear_sprockets_cache
37- React ::JSX . transformer_class = React ::JSX ::JSXTransformer
38- React ::JSX . transform_options = { }
3943 end
4044
4145 test 'asset pipeline should transform JSX' do
4246 get '/assets/example.js'
4347 assert_response :success
44- assert_equal EXPECTED_JS , @response . body
48+
49+ assert_equal EXPECTED_JS . gsub ( /\s / , '' ) , @response . body . gsub ( /\s / , '' )
4550 end
4651
4752 test 'asset pipeline should transform JSX + Coffeescript' do
@@ -51,9 +56,31 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
5156 # as some version inserts an extra "\n" at the beginning.
5257 # Because appraisal is used, multiple versions of coffee-script are treated
5358 # together. Remove all spaces to make test pass.
59+ # puts @response.body
5460 assert_equal EXPECTED_JS_2 . gsub ( /\s / , '' ) , @response . body . gsub ( /\s / , '' )
5561 end
5662
63+ test 'use a custom transformer' do
64+ React ::JSX . transformer_class = NullTransformer
65+ manually_expire_asset ( 'example2.js' )
66+ get '/assets/example2.js'
67+ assert_equal "TRANSFORMED CODE!;\n " , @response . body
68+ end
69+
70+ end
71+
72+ class JSXTransformerTest < ActionDispatch ::IntegrationTest
73+
74+ setup do
75+ clear_sprockets_cache
76+ React ::JSX . transformer_class = React ::JSX ::JSXTransformer
77+ React ::JSX . transform_options = { }
78+ end
79+
80+ teardown do
81+ clear_sprockets_cache
82+ end
83+
5784 test 'can use dropped-in version of JSX transformer' do
5885 hidden_path = Rails . root . join ( "vendor/assets/react/JSXTransformer__.js" )
5986 replacing_path = Rails . root . join ( "vendor/assets/react/JSXTransformer.js" )
@@ -89,7 +116,6 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
89116 replacing_path = custom_path . join ( "CustomTransformer.js" )
90117
91118 React ::JSX . transform_options = { asset_path : "custom/CustomTransformer.js" }
92- React ::JSX . transformer_class = React ::JSX ::JSXTransformer
93119
94120 FileUtils . mkdir_p ( custom_path )
95121 FileUtils . cp ( hidden_path , replacing_path )
@@ -100,10 +126,4 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
100126 assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
101127 end
102128
103- test 'use a custom transformer' do
104- React ::JSX . transformer_class = NullTransformer
105- manually_expire_asset ( 'example2.js' )
106- get '/assets/example2.js'
107- assert_equal "TRANSFORMED CODE!;\n " , @response . body
108- end
109129end
0 commit comments