-
Notifications
You must be signed in to change notification settings - Fork 739
Expand file tree
/
Copy pathtest_helper.rb
More file actions
101 lines (78 loc) · 2.87 KB
/
Copy pathtest_helper.rb
File metadata and controls
101 lines (78 loc) · 2.87 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# frozen_string_literal: true
if RUBY_PLATFORM != "java"
require "simplecov"
SimpleCov.start
end
support_path = File.expand_path("support/*.rb", __dir__)
Dir.glob(support_path).sort.each do |f|
require(f)
end
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require File.expand_path("dummy/config/environment.rb", __dir__)
require "rails/test_help"
require "rails/generators"
require "pathname"
require "minitest/mock"
require "capybara/rails"
require "selenium/webdriver"
require "minitest/retry"
Minitest::Retry.use!
Dummy::Application.load_tasks
ShakapackerHelpers.clear_shakapacker_packs
Capybara.app = Rails.application
Capybara.server = :webrick
Capybara.register_driver :headless_chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox headless=new disable-gpu])
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options, timeout: 300)
end
Capybara.javascript_driver = :headless_chrome
Capybara.current_driver = Capybara.javascript_driver
CACHE_PATH = Pathname.new File.expand_path("dummy/tmp/cache", __dir__)
Rails.backtrace_cleaner.remove_silencers!
def reset_transformer
SprocketsHelpers.clear_sprockets_cache
React::JSX.transformer_class = React::JSX::DEFAULT_TRANSFORMER
React::JSX.transform_options = {}
React::JSX.transformer = nil
end
# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
# Load fixtures from the engine
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
end
ActiveSupport::TestCase.test_order = :random if ActiveSupport::TestCase.respond_to?(:test_order=)
def wait_for_turbolinks_to_be_available
sleep(1)
end
# Different processors may generate slightly different outputs,
# as some version inserts an extra "\n" at the beginning.
# Because appraisal is used, multiple versions of coffee-script are treated
# together. Remove all spaces to make test pass.
def assert_compiled_javascript_matches(javascript, expectation)
assert_equal expectation.gsub(/\s/, ""), javascript.gsub(/\s/, "")
end
def assert_compiled_javascript_includes(javascript, expected_part)
assert_includes javascript.gsub(/\s/, ""), expected_part.gsub(/\s/, "")
end
def when_stateful_js_context_available
return unless defined?(V8) || defined?(MiniRacer)
yield
end
def expected_working_jsx
/\.createElement\(\s*\S*\.Fragment,\s*null,\s*"Name:\s*",\s*this\.props\.name,\s*"Address:\s*",\s*this\.props\.address\s*\)/x # rubocop:disable Layout/LineLength
end
def expected_working_jsx_in_function_component
/\.createElement\(\s*\S*\.Fragment,\s*null,\s*"Name:\s*",\s*props\.name,\s*"Address:\s*",\s*props\.address\s*\)/x
end
module ParamsHelper
# Normalize params for Rails 5.1+
def query_params(params)
if Rails::VERSION::MAJOR > 4
{ params: params }
else
params
end
end
end