Skip to content

Commit 981e3d9

Browse files
committed
feat(renderer) fix asset test
1 parent 486a8ea commit 981e3d9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

test/react_test.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
require 'test_helper'
2-
require 'fileutils'
3-
42
class ReactTest < ActionDispatch::IntegrationTest
53
setup do
6-
Rails.application.assets.send(:expire_index!)
4+
FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist?
5+
6+
end
7+
8+
teardown do
79
FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist?
810
end
911

1012
test 'asset pipeline should deliver drop-in react file replacement' do
1113
app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__)
12-
13-
react_file_token = "'test_confirmation_token_react_content_non_production';\n";
14+
react_file_token = "'test_confirmation_token_react_content_non_production';\n"
1415
File.write(app_react_file_path, react_file_token)
1516

16-
asset_pipeline_length = Rails.application.assets.find_asset('react').to_s.length
17+
react_asset = Rails.application.assets['react.js']
18+
19+
# Sprockets 2 doesn't expire this asset correctly,
20+
# so override `fresh?` to mark it as expired.
21+
def react_asset.fresh?(env); false; end
22+
23+
react_asset = Rails.application.assets['react.js']
24+
1725
get '/assets/react.js'
1826

1927
File.unlink(app_react_file_path)
20-
FileUtils.rm_r CACHE_PATH if CACHE_PATH.exist?
28+
FileUtils.rm_r(CACHE_PATH) if CACHE_PATH.exist?
2129

2230
assert_response :success
23-
assert_equal react_file_token.length, asset_pipeline_length, "The asset pipeline serves the drop-in file"
31+
assert_equal react_file_token.length, react_asset.to_s.length, "The asset pipeline serves the drop-in file"
2432
assert_equal react_file_token.length, @response.body.length, "The asset route serves the drop-in file"
2533
end
2634

0 commit comments

Comments
 (0)