-
Notifications
You must be signed in to change notification settings - Fork 756
/
Copy pathjsx_test.rb
76 lines (58 loc) · 1.92 KB
/
jsx_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true
require "test_helper"
# Sprockets is inserting a newline after the docblock for some reason...
EXPECTED_JS = <<~STR
[2].concat([1]);React.createElement("div", null);
STR
EXPECTED_JS_2 = <<~STR
(function() {
var Component;
Component = createReactClass({
render: function() {
return React.createElement(ExampleComponent, {videos:this.props.videos} );
}
});
this.Component = Component;
}).call(this);
STR
class NullTransformer
def initialize(_options = {}); end # rubocop:disable Style/RedundantInitialize
def transform(_code)
"TRANSFORMED CODE!;\n"
end
end
class JSXTransformTest < ActionDispatch::IntegrationTest
SprocketsHelpers.when_available do
setup do
reset_transformer
end
teardown do
reset_transformer
end
test "asset pipeline should transform JSX" do
SprocketsHelpers.manually_expire_asset("example.js")
get "/assets/example.js"
assert_response :success
assert_compiled_javascript_matches(EXPECTED_JS, @response.body)
end
test "asset pipeline should transform JSX + Coffeescript" do
SprocketsHelpers.manually_expire_asset("example2.js")
get "/assets/example2.js"
assert_response :success
assert_compiled_javascript_matches(EXPECTED_JS_2, @response.body)
end
test "use a custom transformer" do
React::JSX.transformer_class = NullTransformer
SprocketsHelpers.manually_expire_asset("example2.js")
get "/assets/example2.js"
assert_equal "TRANSFORMED CODE!;\n", @response.body
end
def test_babel_transformer_accepts_babel_transformation_options
React::JSX.transform_options = { blacklist: ["spec.functionName", "validation.react", "strict"] }
SprocketsHelpers.manually_expire_asset("example.js")
get "/assets/example.js"
assert_response :success
refute_includes @response.body, "strict"
end
end
end