Skip to content

Commit

Permalink
Move webpack tests to a subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
zzak committed Jan 12, 2024
1 parent e90f88a commit 88bfb43
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
29 changes: 29 additions & 0 deletions test/installer/webpack_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "test_helper"

class WebpackInstallerTest < ActiveSupport::TestCase
include RailsAppHelpers

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 pre-existing Procfile" do
with_new_rails_app do
File.write("Procfile.dev", "pre: existing\n")
_out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_equal "pre: existing\njs: yarn build --watch\n", File.read("Procfile.dev")
end
end
end
34 changes: 5 additions & 29 deletions test/installer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class InstallerTest < ActiveSupport::TestCase

test "installer" do
with_new_rails_app do
out, _err = run_command("bin/rails", "javascript:install:shared")
_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")
Expand All @@ -22,24 +22,9 @@ 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")
_out, _err = run_command("bin/rails", "javascript:install:shared")

assert_match %(/app/assets/builds/*\n!/app/assets/builds/.keep), File.read(".gitignore")
end
Expand All @@ -48,15 +33,15 @@ class InstallerTest < ActiveSupport::TestCase
test "installer with missing .gitignore" do
with_new_rails_app do
FileUtils.rm(".gitignore")
out, _err = run_command("bin/rails", "javascript:install:webpack")
_out, _err = run_command("bin/rails", "javascript:install:shared")

assert_not File.exist?(".gitignore")
end
end

test "installer with pre-existing layouts/application.html.erb" 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_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")
Expand All @@ -66,22 +51,13 @@ class InstallerTest < ActiveSupport::TestCase
test "installer with missing layouts/application.html.erb" do
with_new_rails_app do
FileUtils.rm("app/views/layouts/application.html.erb")
out, _err = run_command("bin/rails", "javascript:install:webpack")
out, _err = run_command("bin/rails", "javascript:install:shared")

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

test "installer with pre-existing Procfile" do
with_new_rails_app do
File.write("Procfile.dev", "pre: existing\n")
out, _err = run_command("bin/rails", "javascript:install:webpack")

assert_equal "pre: existing\njs: yarn build --watch\n", File.read("Procfile.dev")
end
end

private
def with_new_rails_app(&block)
super do
Expand Down

0 comments on commit 88bfb43

Please sign in to comment.