Skip to content

Commit 35e2222

Browse files
committed
Update tests
1 parent ebceee4 commit 35e2222

26 files changed

+83
-83
lines changed

test/dummy/app/controllers/pages_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class PagesController < ApplicationController
4-
per_request_react_rails_prerenderer if WebpackerHelpers.available? || SprocketsHelpers.available?
4+
per_request_react_rails_prerenderer if ShakapackerHelpers.available? || SprocketsHelpers.available?
55

66
def show
77
@prerender = !params[:prerender].nil?

test/dummy/app/views/layouts/application.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<title>Dummy</title>
5-
<% if WebpackerHelpers.available? %>
5+
<% if ShakapackerHelpers.available? %>
66
<%= javascript_include_tag "turbolinks_only", "data-turbolinks-track" => true %>
77
<%= javascript_pack_tag "application" %>
88
<% elsif SprocketsHelpers.available? %>

test/dummy/app/views/pack_components/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= javascript_pack_tag "application" if WebpackerHelpers.available? %>
1+
<%= javascript_pack_tag "application" if ShakapackerHelpers.available? %>
22

33
<!-- Test each way of exporting a component -->
44
<%= react_component("export_default_component") %>

test/dummy/bin/webpacker renamed to test/dummy/bin/shakapacker

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
require "pathname"
55
require "bundler/setup"
6-
require "webpacker"
7-
require "webpacker/webpack_runner"
6+
require "shakapacker"
7+
require "shakapacker/webpack_runner"
88

99
ENV["RAILS_ENV"] ||= "development"
1010
ENV["NODE_ENV"] ||= ENV.fetch("RAILS_ENV", nil)
1111
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
1212

1313
APP_ROOT = File.expand_path("..", __dir__)
1414
Dir.chdir(APP_ROOT) do
15-
Webpacker::WebpackRunner.run(ARGV)
15+
Shakapacker::WebpackRunner.run(ARGV)
1616
end

test/dummy/bin/webpacker-dev-server renamed to test/dummy/bin/shakapacker-dev-server

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
1010

1111
require "bundler/setup"
1212

13-
require "webpacker"
14-
require "webpacker/dev_server_runner"
13+
require "shakapacker"
14+
require "shakapacker/dev_server_runner"
1515

1616
APP_ROOT = File.expand_path("..", __dir__)
1717
Dir.chdir(APP_ROOT) do
18-
Webpacker::DevServerRunner.run(ARGV)
18+
Shakapacker::DevServerRunner.run(ARGV)
1919
end

test/dummy/config/webpacker.yml renamed to test/dummy/config/shakapacker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default: &default
44
source_path: app/javascript
55
source_entry_path: packs
66
public_output_path: packs
7-
cache_path: tmp/cache/webpacker
7+
cache_path: tmp/cache/shakapacker
88

99
# Additional paths webpack should lookup modules
1010
# ['app/assets', 'engine/foo/app/assets']

test/dummy/config/webpack/commonWebpackConfig.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Common configuration applying to client and server configuration
22

3-
const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker')
3+
const { generateWebpackConfig, merge } = require('shakapacker')
4+
5+
const baseClientWebpackConfig = generateWebpackConfig()
46

57
const commonOptions = {
68
resolve: {

test/dummy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^17.0.2",
1818
"react-dom": "^17.0.2",
1919
"react_ujs": "file:.yalc/react_ujs",
20-
"shakapacker": "6.6.0",
20+
"shakapacker": "7.0.2",
2121
"style-loader": "^3.3.1",
2222
"terser-webpack-plugin": "^5.3.3",
2323
"webpack": "^5.73.0",

test/dummy/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3789,10 +3789,10 @@ setprototypeof@1.2.0:
37893789
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.2.0.tgz#66c9a24a73f9fc28cbe66b09fed3d33dcaf1b424"
37903790
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==
37913791

3792-
shakapacker@6.6.0:
3793-
version "6.6.0"
3794-
resolved "https://registry.yarnpkg.com/shakapacker/-/shakapacker-6.6.0.tgz#1e372a7ce6fa93f1a7bd1820737b8168679eb220"
3795-
integrity sha512-7sNnv8PXMlgm2Ob7vZOayLKu0+PPMN3q0HEyAlkFIJtHJt7wA3p1rObhlk0/OrNeBa4dio/9HiBUeEU7bZsHvw==
3792+
shakapacker@7.0.2:
3793+
version "7.0.2"
3794+
resolved "https://registry.yarnpkg.com/shakapacker/-/shakapacker-7.0.2.tgz#cd7cb5075fdbf4d06e60d894f9076c8e56643a98"
3795+
integrity sha512-TF2GFb0E28fvQpn2L6RdvAHJRZmFMTvpJg93102tCbFywHq3tmTqwD/ijvlD+eMuZ8d1i3AMTnhO+45ayN3dYg==
37963796
dependencies:
37973797
glob "^7.2.0"
37983798
js-yaml "^4.1.0"

test/generators/coffee_component_generator_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ class CoffeeComponentGeneratorTest < Rails::Generators::TestCase
88
setup :prepare_destination
99
tests React::Generators::ComponentGenerator
1010

11-
if WebpackerHelpers.available?
11+
if ShakapackerHelpers.available?
1212
def filename
1313
"app/javascript/components/GeneratedComponent.coffee"
1414
end
1515

16-
test "that Webpacker defaults to ES6" do
16+
test "that Shakapacker defaults to ES6" do
1717
run_generator %w[GeneratedComponent name]
1818

1919
es6 = File.read(File.join(destination_root, "app/javascript/components/GeneratedComponent.js"))

test/generators/component_generator_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ComponentGeneratorTest < Rails::Generators::TestCase
88
setup :prepare_destination
99
tests React::Generators::ComponentGenerator
1010

11-
if WebpackerHelpers.available?
11+
if ShakapackerHelpers.available?
1212
def filename
1313
"app/javascript/components/GeneratedComponent.js"
1414
end
@@ -30,18 +30,18 @@ def filename_with_subfolder
3030
run_generator %w[GeneratedComponent]
3131

3232
assert_file filename do |contents|
33-
if WebpackerHelpers.available?
33+
if ShakapackerHelpers.available?
3434
assert_match(/^import React from "react"/, contents)
3535
assert_match(/export default GeneratedComponent\n$/m, contents)
3636
end
3737
end
3838
end
3939

4040
test "creates the component file in a subdirectory" do
41-
puts WebpackerHelpers.available?
41+
puts ShakapackerHelpers.available?
4242
run_generator %w[generated_folder/GeneratedComponent]
4343
assert_file filename_with_subfolder do |contents|
44-
if WebpackerHelpers.available?
44+
if ShakapackerHelpers.available?
4545
assert_match(/^import React from "react"/, contents)
4646
assert_match(/export default GeneratedComponent\n$/m, contents)
4747
end

test/generators/es6_component_generator_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Es6ComponentGeneratorTest < Rails::Generators::TestCase
88
setup :prepare_destination
99
tests React::Generators::ComponentGenerator
1010

11-
if WebpackerHelpers.available?
11+
if ShakapackerHelpers.available?
1212
def filename
1313
"app/javascript/components/GeneratedComponent.js"
1414
end

test/generators/install_generator_sprockets_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
require "test_helper"
44
require "generators/react/install_generator"
55

6-
# If webpacker is available, its setup is preferred
7-
unless WebpackerHelpers.available?
6+
# If Shakapacker is available, its setup is preferred
7+
unless ShakapackerHelpers.available?
88
class InstallGeneratorSprocketsTest < Rails::Generators::TestCase
99
destination File.join(Rails.root, "tmp", "generator_test_output")
1010
tests React::Generators::InstallGenerator

test/generators/install_generator_webpacker_test.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
require "test_helper"
44
require "generators/react/install_generator"
5-
6-
class InstallGeneratorWebpackerTest < Rails::Generators::TestCase
7-
WebpackerHelpers.when_webpacker_available do
5+
class InstallGeneratorShakapackerTest < Rails::Generators::TestCase
6+
ShakapackerHelpers.when_shakapacker_available do
87
destination File.join(Rails.root, "tmp", "generator_test_output")
98
tests React::Generators::InstallGenerator
109
setup :prepare_destination

test/react/rails/component_mount_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def self.react_rails_prerenderer
1919
compiled_once = false
2020
setup do
2121
unless compiled_once
22-
WebpackerHelpers.clear_webpacker_packs
23-
WebpackerHelpers.compile
22+
ShakapackerHelpers.clear_shakapacker_packs
23+
ShakapackerHelpers.compile
2424
end
2525
@helper = React::Rails::ComponentMount.new
2626
end

test/react/rails/controller_lifecycle_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def react_component(*_args)
2727
class ControllerLifecycleTest < ActionDispatch::IntegrationTest
2828
compiled = false
2929
setup do
30-
WebpackerHelpers.compile unless compiled
30+
ShakapackerHelpers.compile unless compiled
31+
3132
@previous_helper_implementation = React::Rails::ViewHelper.helper_implementation_class
3233
React::Rails::ViewHelper.helper_implementation_class = DummyHelperImplementation
3334
end

test/react/rails/pages_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class PagesControllerTest < ActionController::TestCase
66
include ParamsHelper
77
setup do
8-
WebpackerHelpers.compile_if_missing
8+
ShakapackerHelpers.compile_if_missing
99
end
1010

1111
test "renders successfully" do

test/react/rails/react_rails_ujs_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ReactRailsUJSTest < ActionDispatch::IntegrationTest
66
SprocketsHelpers.when_available do
77
include Capybara::DSL
88

9-
# Normalize for webpacker check:
9+
# Normalize for shakapacker check:
1010
def assert_greeting(page, greeting)
1111
assert page.has_content?(greeting), <<~MSG
1212
#{page.body}

test/react/rails/test_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class TestHelperTest < ActionDispatch::IntegrationTest
66
setup do
7-
WebpackerHelpers.compile_if_missing
7+
ShakapackerHelpers.compile_if_missing
88
end
99

1010
test "assert_react_component" do # rubocop:disable Minitest/MultipleAssertions

test/react/rails/webpacker_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
require "test_helper"
44

5-
class ReactRailsWebpackerTest < ActionDispatch::IntegrationTest
6-
WebpackerHelpers.when_webpacker_available do
5+
class ReactRailsShakapackerTest < ActionDispatch::IntegrationTest
6+
ShakapackerHelpers.when_shakapacker_available do
77
include Capybara::DSL
88

99
setup do
1010
Capybara.current_driver = Capybara.javascript_driver
11-
WebpackerHelpers.compile
11+
ShakapackerHelpers.compile
1212
React::ServerRendering.reset_pool
1313
end
1414

1515
teardown do
16-
WebpackerHelpers.clear_webpacker_packs
16+
ShakapackerHelpers.clear_shakapacker_packs
1717
end
1818

1919
test "it mounts components from the pack" do # rubocop:disable Minitest/MultipleAssertions

test/react/server_rendering/bundle_renderer_test.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
require "test_helper"
44

5-
if SprocketsHelpers.available? || WebpackerHelpers.available?
5+
if SprocketsHelpers.available? || ShakapackerHelpers.available?
66
class BundleRendererTest < ActiveSupport::TestCase
77
CALLBACKS = %i[before_render after_render].freeze
88

9-
webpacker_compiled = false
9+
shakapacker_compiled = false
1010
setup do
11-
if WebpackerHelpers.available? && !webpacker_compiled
12-
WebpackerHelpers.compile
13-
webpacker_compiled = true
11+
if ShakapackerHelpers.available? && !shakapacker_compiled
12+
ShakapackerHelpers.compile
13+
shakapacker_compiled = true
1414
end
1515
@renderer = React::ServerRendering::BundleRenderer.new({})
1616
end
@@ -91,22 +91,20 @@ class BundleRendererTest < ActiveSupport::TestCase
9191
assert_match(/console.error.apply\(console, \["setTimeout #{message}"\]\);$/, result)
9292
end
9393

94-
unless WebpackerHelpers.available?
95-
# This doesn't work with webpacker since finding components is based on filename
94+
unless ShakapackerHelpers.available?
95+
# This doesn't work with Shakapacker since finding components is based on filename
9696
test ".new accepts additional code to add to the JS context" do
9797
additional_code = File.read(File.expand_path("../../helper_files/WithoutSprockets.js", __dir__))
98-
9998
additional_renderer = React::ServerRendering::BundleRenderer.new(code: additional_code)
10099

101100
assert_match(%r{drink more caffeine</span>},
102101
additional_renderer.render("WithoutSprockets", { label: "drink more caffeine" }, nil))
103102
end
104103

105-
# These use cases don't apply to Webpacker since the require.context comes from a pack:
104+
# These use cases don't apply to Shakapacker since the require.context comes from a pack:
106105
test ".new accepts any filenames" do
107106
limited_renderer = React::ServerRendering::BundleRenderer.new(files: ["react-server.js", "react_ujs.js",
108107
"components/Todo.js"])
109-
110108
assert_match(%r{get a real job</li>}, limited_renderer.render("Todo", { todo: "get a real job" }, nil))
111109
err = assert_raises React::ServerRendering::PrerenderError do
112110
limited_renderer.render("TodoList", { todos: [] }, nil)

test/react/server_rendering/console_replay_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
require "test_helper"
44

5-
if WebpackerHelpers.available? || SprocketsHelpers.available?
5+
if ShakapackerHelpers.available? || SprocketsHelpers.available?
66
class ConsoleReplayTest < ActionDispatch::IntegrationTest
77
setup do
8-
WebpackerHelpers.compile
8+
ShakapackerHelpers.compile
99
React::ServerRendering.renderer_options = { replay_console: true }
1010
React::ServerRendering.reset_pool
1111
end

test/react/server_rendering/webpacker_containers_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
require "test_helper"
44
require "open-uri"
55

6-
class WebpackerManifestContainerTest < ActiveSupport::TestCase
7-
WebpackerHelpers.when_webpacker_available do
6+
class ShakapackerManifestContainerTest < ActiveSupport::TestCase
7+
ShakapackerHelpers.when_shakapacker_available do
88
setup do
9-
WebpackerHelpers.clear_webpacker_packs
9+
ShakapackerHelpers.clear_shakapacker_packs
1010
end
1111

12-
def test_it_loads_js_from_the_webpacker_container
13-
WebpackerHelpers.compile
12+
def test_it_loads_js_from_the_shakapacker_container
13+
ShakapackerHelpers.compile
1414
container = React::ServerRendering::SeparateServerBundleContainer.new
1515

1616
assert_not_empty container.find_asset("server_rendering.js")

test/server_rendered_html_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def wait_to_ensure_asset_pipeline_detects_changes
1313
end
1414

1515
setup do
16-
WebpackerHelpers.compile if WebpackerHelpers.available?
16+
ShakapackerHelpers.compile if ShakapackerHelpers.available?
1717
end
1818

1919
test "react server rendering reloads jsx after changes to the jsx files" do
20-
if WebpackerHelpers.available?
20+
if ShakapackerHelpers.available?
2121
file_with_updates = File.expand_path("helper_files/TodoListWithUpdates.js", __dir__)
2222
file_without_updates = File.expand_path("helper_files/TodoListWithoutUpdates.js", __dir__)
2323
app_file = File.expand_path("../#{DUMMY_LOCATION}/app/javascript/components/TodoList.js", __FILE__)
@@ -38,8 +38,8 @@ def wait_to_ensure_asset_pipeline_detects_changes
3838

3939
FileUtils.cp file_with_updates, app_file
4040
FileUtils.touch app_file
41-
if WebpackerHelpers.available?
42-
WebpackerHelpers.compile
41+
if ShakapackerHelpers.available?
42+
ShakapackerHelpers.compile
4343
else
4444
wait_to_ensure_asset_pipeline_detects_changes
4545
end
@@ -60,24 +60,24 @@ def wait_to_ensure_asset_pipeline_detects_changes
6060
get "/server/1?component_name=NewList"
6161
end
6262

63-
if WebpackerHelpers.available?
63+
if ShakapackerHelpers.available?
6464
new_file_path = "../#{DUMMY_LOCATION}/app/javascript/components/NewList.js"
65-
new_file_contents = <<~HEREDOC
65+
new_file_contents = <<~JS
6666
var React = require("react")
6767
module.exports = function() { return <span>"New List"</span> }
68-
HEREDOC
68+
JS
6969
else
7070
new_file_path = "../#{DUMMY_LOCATION}/app/assets/javascripts/components/ZZ_NewComponent.js.jsx"
71-
new_file_contents = <<~HEREDOC
71+
new_file_contents = <<~JS
7272
var NewList = function() { return <span>"New List"</span> }
73-
HEREDOC
73+
JS
7474
end
7575

7676
new_file_path = File.expand_path(new_file_path, __FILE__)
7777
File.write new_file_path, new_file_contents
7878

79-
if WebpackerHelpers.available?
80-
WebpackerHelpers.compile
79+
if ShakapackerHelpers.available?
80+
ShakapackerHelpers.compile
8181
else
8282
wait_to_ensure_asset_pipeline_detects_changes
8383
FileUtils.touch new_file_path
@@ -95,7 +95,7 @@ def wait_to_ensure_asset_pipeline_detects_changes
9595
# Make sure console messages are replayed when requested
9696
React::ServerRendering.renderer_options = { replay_console: true }
9797
React::ServerRendering.reset_pool
98-
get "/server/console_example"
98+
get "/server/console_example"
9999

100100
assert_match(/Console Logged/, response.body)
101101
assert_match(/console.log.apply\(console, \["got initial state"\]\)/, response.body)

0 commit comments

Comments
 (0)