2121eos
2222
2323class JSXTransformTest < ActionDispatch ::IntegrationTest
24+ setup { clear_sprockets_cache }
25+ teardown { clear_sprockets_cache }
2426
2527 test 'asset pipeline should transform JSX' do
2628 get '/assets/example.js'
@@ -40,14 +42,12 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
4042 end
4143
4244 test 'can use dropped-in version of JSX transformer' do
43- hidden_path = File . expand_path ( "../dummy/ vendor/assets/react/JSXTransformer__.js", __FILE__ )
44- replacing_path = File . expand_path ( "../dummy/ vendor/assets/react/JSXTransformer.js", __FILE__ )
45+ hidden_path = Rails . root . join ( " vendor/assets/react/JSXTransformer__.js")
46+ replacing_path = Rails . root . join ( " vendor/assets/react/JSXTransformer.js")
4547
46- FileUtils . mv hidden_path , replacing_path
48+ FileUtils . cp hidden_path , replacing_path
4749 get '/assets/example3.js'
48-
49- FileUtils . mv replacing_path , hidden_path
50- FileUtils . rm_r CACHE_PATH if CACHE_PATH . exist?
50+ FileUtils . rm replacing_path
5151
5252 assert_response :success
5353 assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
@@ -69,4 +69,20 @@ class JSXTransformTest < ActionDispatch::IntegrationTest
6969 assert_response :success
7070 assert_match ( /\( i\s *,\s *name\s *\) \s *\{ / , @response . body , "type annotations are removed" )
7171 end
72+
73+ test 'accepts asset_path: option' do
74+ hidden_path = Rails . root . join ( "vendor/assets/react/JSXTransformer__.js" )
75+ custom_path = Rails . root . join ( "vendor/assets/react/custom" )
76+ replacing_path = custom_path . join ( "CustomTransformer.js" )
77+
78+ React ::JSX . transform_options = { asset_path : "custom/CustomTransformer.js" }
79+
80+ FileUtils . mkdir_p ( custom_path )
81+ FileUtils . cp ( hidden_path , replacing_path )
82+ get '/assets/example3.js'
83+
84+ FileUtils . rm_rf custom_path
85+ assert_response :success
86+ assert_equal 'test_confirmation_token_jsx_transformed;' , @response . body
87+ end
7288end
0 commit comments