Skip to content

Commit 212d159

Browse files
Register tests directory for rails stats (#2129)
* Register tests directory for rails stats * Update docs/CHANGELOG.md * Update docs/CHANGELOG.md --------- Co-authored-by: Joel Hawksley <[email protected]> Co-authored-by: Joel Hawksley <[email protected]>
1 parent 1fd89a4 commit 212d159

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Register ViewComponent tests directory for `rails stats`.
14+
15+
*Javier Aranda*
16+
1317
* Wrap entire compile step in a mutex to make it more resilient to race conditions.
1418

1519
*Blake Williams*

lib/view_component/engine.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ class Engine < Rails::Engine # :nodoc:
1515
else
1616
initializer "view_component.stats_directories" do |app|
1717
require "rails/code_statistics"
18-
dir = ViewComponent::Base.view_component_path
19-
Rails::CodeStatistics.register_directory("ViewComponents", dir)
18+
19+
if Rails.root.join(ViewComponent::Base.view_component_path).directory?
20+
Rails::CodeStatistics.register_directory("ViewComponents", ViewComponent::Base.view_component_path)
21+
end
22+
23+
if Rails.root.join("test/components").directory?
24+
Rails::CodeStatistics.register_directory("ViewComponent tests", "test/components", test_directory: true)
25+
end
2026
end
2127
end
2228

lib/view_component/rails/tasks/view_component.rake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ namespace :view_component do
77
# :nocov:
88
require "rails/code_statistics"
99

10-
dir = ViewComponent::Base.view_component_path
11-
::STATS_DIRECTORIES << ["ViewComponents", dir] if File.directory?(Rails.root + dir)
10+
if Rails.root.join(ViewComponent::Base.view_component_path).directory?
11+
::STATS_DIRECTORIES << ["ViewComponents", ViewComponent::Base.view_component_path]
12+
end
13+
14+
if Rails.root.join("test/components").directory?
15+
::STATS_DIRECTORIES << ["ViewComponent tests", "test/components"]
16+
CodeStatistics::TEST_TYPES << "ViewComponent tests"
17+
end
1218
# :nocov:
1319
end
1420
end

0 commit comments

Comments
 (0)