Skip to content

Commit

Permalink
Allow non-system tests to optionally rely on vite build
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbrictson committed Apr 10, 2024
1 parent 4459bfc commit 57b10a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
12 changes: 8 additions & 4 deletions lib/nextgen/generators/vite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@
add_yarn_packages "postcss@^8.4.24", "autoprefixer@^10.4.14"
copy_file "postcss.config.cjs"

say_git "Disable autoBuild in test environment"
gsub_file "config/vite.json", /("test": \{.+?"autoBuild":\s*)true/m, '\1false'
copy_test_support_file "vite.rb"
# TODO: rspec support
if File.exist?("test/application_system_test_case.rb")
say_git "Disable autoBuild in test environment"
gsub_file "config/vite.json", /("test": \{.+?"autoBuild":\s*)true/m, '\1false'
copy_file "test/vite_helper.rb"
inject_into_file "test/application_system_test_case.rb", "\nrequire \"vite_helper\"", after: /require "test_helper"$/
end

say_git "Install modern-normalize and base stylesheets"
add_yarn_package "modern-normalize@^2.0.0"
Expand Down Expand Up @@ -84,7 +88,7 @@
copy_file "app/helpers/inline_svg_helper.rb"
copy_file "app/frontend/images/example.svg"
# TODO: rspec support
copy_file "test/helpers/inline_svg_helper_test.rb" if minitest?
copy_file "test/helpers/inline_svg_helper_test.rb" if File.exist?("test/vite_helper.rb")

say_git "Add a `yarn start` script"
start = "concurrently -i -k --kill-others-on-fail -p none 'RUBY_DEBUG_OPEN=true bin/rails s' 'bin/vite dev'"
Expand Down
1 change: 1 addition & 0 deletions template/test/helpers/inline_svg_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test_helper"
require "vite_helper"

class InlineSvgHelperTest < ActionView::TestCase
test "inline_svg_tag returns contents of svg file as html_safe string" do
Expand Down
7 changes: 0 additions & 7 deletions template/test/support/vite.rb

This file was deleted.

5 changes: 5 additions & 0 deletions template/test/vite_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return if ViteRuby.config.auto_build

# Compile assets once at the start of testing
millis = Benchmark.ms { ViteRuby.commands.build }
puts format("Built Vite assets (%.1fms)", millis)

0 comments on commit 57b10a7

Please sign in to comment.