Skip to content

Commit

Permalink
Add tests for webpack, other parts of shared installer stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
zzak committed Jan 12, 2024
1 parent 1240776 commit 5878a64
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions test/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class InstallerTest < ActiveSupport::TestCase

test "installer" do
with_new_rails_app do
out, _err = run_command("bin/rails", "javascript:install:webpack")
out, _err = run_command("bin/rails", "javascript:install:shared")

assert_equal 0, File.size("app/assets/builds/.keep")
assert_match "/app/assets/builds/*\n!/app/assets/builds/.keep", File.read(".gitignore")
assert_equal File.read("#{__dir__}/../lib/install/webpack/webpack.config.js"), File.read("webpack.config.js")
assert_equal File.read("#{__dir__}/../lib/install/Procfile.dev"), File.read("Procfile.dev")
assert_equal File.read("#{__dir__}/../lib/install/application.js"), File.read("app/javascript/application.js")
assert_equal File.read("#{__dir__}/../lib/install/package.json"), File.read("package.json")
assert_equal File.read("#{__dir__}/../lib/install/dev"), File.read("bin/dev")
assert_equal 0700, File.stat("bin/dev").mode & 0700

Expand All @@ -22,6 +22,29 @@ class InstallerTest < ActiveSupport::TestCase
end
end

test "installer for webpack" do
with_new_rails_app do
out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_equal File.read("#{__dir__}/../lib/install/Procfile.dev"), File.read("Procfile.dev")
assert_equal File.read("#{__dir__}/../lib/install/webpack/webpack.config.js"), File.read("webpack.config.js")

if sprockets?
assert_match "//= link_tree ../images", File.read("app/assets/config/manifest.js")
assert_match "//= link_directory ../stylesheets .css", File.read("app/assets/config/manifest.js")
assert_match "//= link_tree ../builds", File.read("app/assets/config/manifest.js")
end
end
end

test "installer with .gitignore" do
with_new_rails_app do
out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_match %(/app/assets/builds/*\n!/app/assets/builds/.keep), File.read(".gitignore")
end
end

test "installer with missing .gitignore" do
with_new_rails_app do
FileUtils.rm(".gitignore")
Expand All @@ -31,12 +54,22 @@ class InstallerTest < ActiveSupport::TestCase
end
end

test "installer with pre-existing application.scss" do
test "installer with pre-existing layouts/application.html.erb" do
with_new_rails_app do
out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_match %(Add JavaScript include tag in application layout), out
assert_match %(<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>), File.read("app/views/layouts/application.html.erb")
end
end

test "installer with missing layouts/application.html.erb" do
with_new_rails_app do
File.write("app/assets/stylesheets/application.scss", "// pre-existing")
FileUtils.rm("app/views/layouts/application.html.erb")
out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_equal "// pre-existing", File.read("app/assets/stylesheets/application.scss")
assert_match %(Default application.html.erb is missing!), out
assert_match %(Add <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %> within the <head> tag in your custom layout.), out
end
end

Expand Down

0 comments on commit 5878a64

Please sign in to comment.