|
| 1 | +require 'app_helper' |
| 2 | + |
| 3 | +class InstallerTest < ActiveSupport::TestCase |
| 4 | + include RailsAppHelpers |
| 5 | + include ActiveSupport::Testing::Isolation |
| 6 | + |
| 7 | + test "installer" do |
| 8 | + with_new_rails_app do |
| 9 | + if Rails::VERSION::MAJOR >= 7 && File.read("Gemfile").match?(/importmap-rails/) |
| 10 | + run_command("bin/rails", "importmap:install") |
| 11 | + end |
| 12 | + run_command("bin/rails", "turbo:install") |
| 13 | + |
| 14 | + if Gem::Version.new(Rails.version) >= Gem::Version.new("7.0") |
| 15 | + assert_match %(import "@hotwired/turbo-rails"\n), File.read("app/javascript/application.js") |
| 16 | + end |
| 17 | + |
| 18 | + if Rails::VERSION::MAJOR >= 7 |
| 19 | + assert_match %(pin "@hotwired/turbo-rails", to: "turbo.min.js"), File.read("config/importmap.rb") |
| 20 | + else |
| 21 | + assert_match "@hotwired/turbo-rails", File.read("package.json") |
| 22 | + assert_match "@hotwired/turbo-rails", File.read("yarn.lock") |
| 23 | + end |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + test "installer with no javascript" do |
| 28 | + with_new_rails_app %w[--skip-javascript] do |
| 29 | + out, = run_command("bin/rails", "turbo:install") |
| 30 | + |
| 31 | + assert_match "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.", out |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + test "installer with pre-existing application.js" do |
| 36 | + with_new_rails_app do |
| 37 | + if Rails::VERSION::MAJOR >= 7 && File.read("Gemfile").match?(/importmap-rails/) |
| 38 | + run_command("bin/rails", "importmap:install") |
| 39 | + end |
| 40 | + File.write("app/javascript/application.js", "// pre-existing") |
| 41 | + run_command("bin/rails", "turbo:install") |
| 42 | + |
| 43 | + assert_match "// pre-existing", File.read("app/javascript/application.js") |
| 44 | + assert_match %(import "@hotwired/turbo-rails"\n), File.read("app/javascript/application.js") |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + if Gem::Version.new(Rails.version) >= Gem::Version.new("7.1") |
| 49 | + test "installer with bun" do |
| 50 | + with_new_rails_app %w[--javascript=bun] do |
| 51 | + run_command("bin/rails", "javascript:install:bun") |
| 52 | + run_command("bin/rails", "turbo:install") |
| 53 | + |
| 54 | + assert_match %(import "@hotwired/turbo-rails"\n), File.read("app/javascript/application.js") |
| 55 | + |
| 56 | + assert_match "@hotwired/turbo-rails", File.read("package.json") |
| 57 | + end |
| 58 | + end |
| 59 | + end |
| 60 | +end |
0 commit comments