shakapacker 7.0.0.rc.0 → 7.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +4 -8
  3. data/.github/workflows/dummy.yml +21 -0
  4. data/.github/workflows/generator.yml +37 -0
  5. data/.github/workflows/jest.yml +2 -2
  6. data/.github/workflows/js-lint.yml +2 -2
  7. data/.github/workflows/rubocop.yml +1 -1
  8. data/.github/workflows/ruby-backward-compatibility.yml +2 -6
  9. data/.github/workflows/ruby.yml +2 -6
  10. data/.gitignore +3 -0
  11. data/CHANGELOG.md +17 -18
  12. data/CONTRIBUTING.md +76 -20
  13. data/README.md +5 -1
  14. data/Rakefile +44 -8
  15. data/docs/deployment.md +1 -2
  16. data/lib/install/binstubs.rb +3 -1
  17. data/lib/install/config/shakapacker.yml +9 -0
  18. data/lib/install/config/webpack/webpack.config.js +3 -2
  19. data/lib/install/template.rb +27 -15
  20. data/lib/shakapacker/deprecation_helper.rb +4 -5
  21. data/lib/shakapacker/version.rb +1 -1
  22. data/lib/tasks/shakapacker/check_binstubs.rake +14 -10
  23. data/lib/tasks/shakapacker/compile.rake +1 -6
  24. data/package/__tests__/index-bc.js +22 -0
  25. data/package/environments/__tests__/base-bc.js +2 -2
  26. data/package/environments/__tests__/base.js +2 -2
  27. data/package/environments/__tests__/development.js +53 -0
  28. data/package/environments/__tests__/production.js +53 -0
  29. data/package/environments/base.js +4 -3
  30. data/package/environments/production.js +9 -0
  31. data/package/index.js +24 -1
  32. data/package/utils/helpers.js +1 -1
  33. data/package.json +1 -1
  34. data/spec/dummy/.browserslistrc +1 -0
  35. data/spec/dummy/.gitignore +20 -0
  36. data/spec/dummy/.prettierrc.yaml +4 -0
  37. data/spec/dummy/Gemfile +63 -0
  38. data/spec/dummy/Procfile.dev +5 -0
  39. data/spec/dummy/Procfile.dev-static +9 -0
  40. data/spec/dummy/README.md +1 -0
  41. data/spec/dummy/Rakefile +6 -0
  42. data/spec/dummy/app/assets/config/manifest.js +2 -0
  43. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  44. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  45. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  46. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  47. data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
  48. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  49. data/spec/dummy/app/javascript/Globals.d.ts +3 -0
  50. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
  51. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
  52. data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
  53. data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
  54. data/spec/dummy/app/javascript/packs/application.js +17 -0
  55. data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
  56. data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
  57. data/spec/dummy/app/jobs/application_job.rb +7 -0
  58. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  59. data/spec/dummy/app/models/application_record.rb +3 -0
  60. data/spec/dummy/app/models/concerns/.keep +0 -0
  61. data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
  62. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  63. data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
  64. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  65. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  66. data/spec/dummy/babel.config.js +30 -0
  67. data/spec/dummy/bin/bundle +114 -0
  68. data/spec/dummy/bin/dev +30 -0
  69. data/spec/dummy/bin/dev-static +30 -0
  70. data/spec/dummy/bin/rails +9 -0
  71. data/spec/dummy/bin/rake +9 -0
  72. data/spec/dummy/bin/setup +33 -0
  73. data/spec/dummy/bin/shakapacker +13 -0
  74. data/spec/dummy/bin/shakapacker-dev-server +13 -0
  75. data/spec/dummy/bin/spring +17 -0
  76. data/spec/dummy/bin/yarn +18 -0
  77. data/spec/dummy/config/application.rb +32 -0
  78. data/spec/dummy/config/boot.rb +4 -0
  79. data/spec/dummy/config/cable.yml +10 -0
  80. data/spec/dummy/config/credentials.yml.enc +1 -0
  81. data/spec/dummy/config/database.yml +25 -0
  82. data/spec/dummy/config/environment.rb +5 -0
  83. data/spec/dummy/config/environments/development.rb +54 -0
  84. data/spec/dummy/config/environments/production.rb +106 -0
  85. data/spec/dummy/config/environments/test.rb +49 -0
  86. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  87. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  88. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  89. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  90. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  91. data/spec/dummy/config/initializers/inflections.rb +16 -0
  92. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  93. data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
  94. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  95. data/spec/dummy/config/locales/en.yml +33 -0
  96. data/spec/dummy/config/puma.rb +38 -0
  97. data/spec/dummy/config/routes.rb +6 -0
  98. data/spec/dummy/config/shakapacker.yml +62 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/config/storage.yml +34 -0
  101. data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
  102. data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
  103. data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
  104. data/spec/dummy/config/webpack/development.js +32 -0
  105. data/spec/dummy/config/webpack/production.js +9 -0
  106. data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
  107. data/spec/dummy/config/webpack/test.js +7 -0
  108. data/spec/dummy/config/webpack/webpack.config.js +24 -0
  109. data/spec/dummy/config.ru +5 -0
  110. data/spec/dummy/db/seeds.rb +7 -0
  111. data/spec/dummy/lib/assets/.keep +0 -0
  112. data/spec/dummy/lib/tasks/.keep +0 -0
  113. data/spec/dummy/package.json +44 -0
  114. data/spec/dummy/postcss.config.js +12 -0
  115. data/spec/dummy/public/404.html +67 -0
  116. data/spec/dummy/public/422.html +67 -0
  117. data/spec/dummy/public/500.html +66 -0
  118. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  119. data/spec/dummy/public/apple-touch-icon.png +0 -0
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/dummy/public/robots.txt +1 -0
  122. data/spec/dummy/spec/rails_helper.rb +118 -0
  123. data/spec/dummy/spec/spec_helper.rb +96 -0
  124. data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
  125. data/spec/dummy/tsconfig.json +21 -0
  126. data/spec/dummy/vendor/.keep +0 -0
  127. data/spec/dummy/yarn.lock +4697 -0
  128. data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
  129. data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
  130. data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
  131. data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
  132. data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
  133. data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
  134. data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
  135. data/spec/generator_specs/e2e_template/template.rb +21 -0
  136. data/spec/generator_specs/generator_spec.rb +169 -0
  137. data/spec/{configuration_spec.rb → shakapacker/configuration_spec.rb} +10 -10
  138. data/spec/{dev_server_runner_spec.rb → shakapacker/dev_server_runner_spec.rb} +1 -1
  139. data/spec/{engine_rake_tasks_spec.rb → shakapacker/engine_rake_tasks_spec.rb} +2 -2
  140. data/spec/{manifest_spec.rb → shakapacker/manifest_spec.rb} +1 -1
  141. data/spec/shakapacker/rake_tasks_spec.rb +93 -0
  142. data/spec/{spec_helper_initializer.rb → shakapacker/spec_helper_initializer.rb} +1 -1
  143. data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
  144. data/spec/shakapacker/test_app/some.config.js +0 -0
  145. data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +9 -9
  146. data/spec/{webpack_runner_spec.rb → shakapacker/webpack_runner_spec.rb} +1 -1
  147. metadata +173 -64
  148. data/gemfiles/Gemfile-rails.5.2.x +0 -9
  149. data/spec/rake_tasks_spec.rb +0 -34
  150. /data/docs/{developing_webpacker.md → developing_shakapacker.md} +0 -0
  151. /data/spec/backward_compatibility_specs/{command_spec_bc.rb → command_spec.rb} +0 -0
  152. /data/spec/backward_compatibility_specs/{compiler_spec_bc.rb → compiler_spec.rb} +0 -0
  153. /data/spec/backward_compatibility_specs/{compiler_strategy_spec_bc.rb → compiler_strategy_spec.rb} +0 -0
  154. /data/spec/backward_compatibility_specs/{configuration_spec_bc.rb → configuration_spec.rb} +0 -0
  155. /data/spec/backward_compatibility_specs/{dev_server_runner_spec_bc.rb → dev_server_runner_spec.rb} +0 -0
  156. /data/spec/backward_compatibility_specs/{dev_server_spec_bc.rb → dev_server_spec.rb} +0 -0
  157. /data/spec/backward_compatibility_specs/{digest_strategy_spec_bc.rb → digest_strategy_spec.rb} +0 -0
  158. /data/spec/backward_compatibility_specs/{engine_rake_tasks_spec_bc.rb → engine_rake_tasks_spec.rb} +0 -0
  159. /data/spec/backward_compatibility_specs/{env_spec_bc.rb → env_spec.rb} +0 -0
  160. /data/spec/backward_compatibility_specs/{helper_spec_bc.rb → helper_spec.rb} +0 -0
  161. /data/spec/backward_compatibility_specs/{instance_spec_bc.rb → instance_spec.rb} +0 -0
  162. /data/spec/backward_compatibility_specs/{manifest_spec_bc.rb → manifest_spec.rb} +0 -0
  163. /data/spec/backward_compatibility_specs/{mtime_strategy_spec_bc.rb → mtime_strategy_spec.rb} +0 -0
  164. /data/spec/backward_compatibility_specs/{rake_tasks_spec_bc.rb → rake_tasks_spec.rb} +0 -0
  165. /data/spec/backward_compatibility_specs/{webpack_runner_spec_bc.rb → webpack_runner_spec.rb} +0 -0
  166. /data/spec/backward_compatibility_specs/{webpacker_spec_bc.rb → webpacker_spec.rb} +0 -0
  167. /data/spec/{test_app/config/webpack/webpack.config.js → dummy/app/assets/images/.keep} +0 -0
  168. /data/spec/{test_app/some.config.js → dummy/app/controllers/concerns/.keep} +0 -0
  169. /data/spec/{command_spec.rb → shakapacker/command_spec.rb} +0 -0
  170. /data/spec/{compiler_spec.rb → shakapacker/compiler_spec.rb} +0 -0
  171. /data/spec/{compiler_strategy_spec.rb → shakapacker/compiler_strategy_spec.rb} +0 -0
  172. /data/spec/{dev_server_spec.rb → shakapacker/dev_server_spec.rb} +0 -0
  173. /data/spec/{digest_strategy_spec.rb → shakapacker/digest_strategy_spec.rb} +0 -0
  174. /data/spec/{env_spec.rb → shakapacker/env_spec.rb} +0 -0
  175. /data/spec/{helper_spec.rb → shakapacker/helper_spec.rb} +0 -0
  176. /data/spec/{instance_spec.rb → shakapacker/instance_spec.rb} +0 -0
  177. /data/spec/{mtime_strategy_spec.rb → shakapacker/mtime_strategy_spec.rb} +0 -0
  178. /data/spec/{webpacker_spec.rb → shakapacker/shakapacker_spec.rb} +0 -0
  179. /data/spec/{test_app → shakapacker/test_app}/.gitignore +0 -0
  180. /data/spec/{test_app → shakapacker/test_app}/Rakefile +0 -0
  181. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/application.js +0 -0
  182. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/generated/something.js +0 -0
  183. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.css +0 -0
  184. /data/spec/{test_app → shakapacker/test_app}/app/javascript/entrypoints/multi_entry.js +0 -0
  185. /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker +0 -0
  186. /data/spec/{test_app → shakapacker/test_app}/bin/shakapacker-dev-server +0 -0
  187. /data/spec/{test_app → shakapacker/test_app}/config/application.rb +0 -0
  188. /data/spec/{test_app → shakapacker/test_app}/config/environment.rb +0 -0
  189. /data/spec/{test_app → shakapacker/test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
  190. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker.yml +0 -0
  191. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -0
  192. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_defaults_fallback.yml +0 -0
  193. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_manifest_path.yml +0 -0
  194. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_nested_entries.yml +0 -0
  195. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_no_precompile.yml +0 -0
  196. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_other_location.yml +0 -0
  197. /data/spec/{test_app → shakapacker/test_app}/config/shakapacker_public_root.yml +0 -0
  198. /data/spec/{test_app → shakapacker/test_app}/config.ru +0 -0
  199. /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
  200. /data/spec/{test_app → shakapacker/test_app}/public/packs/manifest.json +0 -0
  201. /data/spec/{test_app → shakapacker/test_app}/yarn.lock +0 -0
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ import React from 'react'
2
+
3
+ function App() {
4
+ return (
5
+ <div className="App">
6
+ <h1>App component</h1>
7
+ <p>Text from react component!</p>
8
+ </div>
9
+ )
10
+ }
11
+
12
+ export default App
@@ -0,0 +1,10 @@
1
+ import React from 'react'
2
+ import ReactDOM from 'react-dom/client'
3
+ import App from '../components/App'
4
+
5
+ const root = ReactDOM.createRoot(document.getElementById('root'))
6
+ root.render(
7
+ <React.StrictMode>
8
+ <App />
9
+ </React.StrictMode>
10
+ )
@@ -0,0 +1,2 @@
1
+ <h1>Home#index</h1>
2
+ <p>Find me in app/views/home/index.html.erb</p>
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Sh7InstallTest</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <%= csrf_meta_tags %>
7
+ <%= csp_meta_tag %>
8
+
9
+ <%= stylesheet_link_tag "application" %>
10
+ <%= javascript_pack_tag "application" %>
11
+ </head>
12
+
13
+ <body>
14
+ <%= yield %>
15
+ <div id="root"></div>
16
+ </body>
17
+ </html>
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ get "home/index"
3
+ end
@@ -0,0 +1,13 @@
1
+ require "rails_helper"
2
+
3
+ RSpec.describe "home/index", type: :system, js: true do
4
+ before do
5
+ driven_by(:selenium_headless)
6
+ end
7
+
8
+ it "renders the App component" do
9
+ visit "home/index"
10
+
11
+ expect(page.body).to match "App component"
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # install react
2
+ system("yarn add react react-dom @babel/preset-react")
3
+
4
+ # update webpack presets for react
5
+ package_json_path = Rails.root.join("./package.json")
6
+ insert_into_file(
7
+ package_json_path,
8
+ %( "@babel/preset-react",\n),
9
+ after: /"presets": \[\n/
10
+ )
11
+
12
+ # install rspec-rails
13
+ system("bundle add rspec-rails --group development,test")
14
+ system("bundle exec rails g rspec:install")
15
+
16
+ # copy files
17
+ directory(
18
+ Rails.root.join("../e2e_template/files"),
19
+ Rails.root,
20
+ force: true
21
+ )
@@ -0,0 +1,169 @@
1
+ require "pathname"
2
+ require "rake"
3
+ require "json"
4
+ require "shakapacker/utils/misc"
5
+ require "shakapacker/utils/version_syntax_converter"
6
+
7
+ GEM_ROOT = Pathname.new(File.expand_path("../../..", __FILE__))
8
+ SPEC_PATH = Pathname.new(File.expand_path("../", __FILE__))
9
+ BASE_RAILS_APP_PATH = SPEC_PATH.join("base-rails-app")
10
+ TEMP_RAILS_APP_PATH = SPEC_PATH.join("temp-rails-app")
11
+
12
+ describe "Generator" do
13
+ before :all do
14
+ # Don't use --skip-git because we want .gitignore file to exist in the project
15
+ sh_in_dir(SPEC_PATH, %(
16
+ rails new base-rails-app --skip-javascript --skip-bundle --skip-spring
17
+ rm -rf base-rails-app/.git
18
+ ))
19
+
20
+ Bundler.with_unbundled_env do
21
+ sh_in_dir(BASE_RAILS_APP_PATH, %(
22
+ gem update bundler
23
+ bundle add shakapacker --path "#{GEM_ROOT}"
24
+ ))
25
+ end
26
+ end
27
+
28
+ after :all do
29
+ Dir.chdir(SPEC_PATH)
30
+ FileUtils.rm_rf(BASE_RAILS_APP_PATH)
31
+ end
32
+
33
+ describe "shakapacker:install" do
34
+ context "in a normal Rails project" do
35
+ before :all do
36
+ sh_in_dir(SPEC_PATH, "cp -r #{BASE_RAILS_APP_PATH} #{TEMP_RAILS_APP_PATH}")
37
+
38
+ Bundler.with_unbundled_env do
39
+ sh_in_dir(TEMP_RAILS_APP_PATH, "FORCE=true bundle exec rails shakapacker:install")
40
+ end
41
+ end
42
+
43
+ after :all do
44
+ Dir.chdir(SPEC_PATH)
45
+ FileUtils.rm_rf(TEMP_RAILS_APP_PATH)
46
+ end
47
+
48
+ it "creates `config/shakapacker.yml`" do
49
+ config_file_relative_path = "config/shakapacker.yml"
50
+ actual_content = read(path_in_the_app(config_file_relative_path))
51
+ expected_content = read(path_in_the_gem(config_file_relative_path))
52
+
53
+ expect(actual_content).to eq expected_content
54
+ end
55
+
56
+ it "replaces package.json with template file" do
57
+ actual_content = read(path_in_the_app("package.json"))
58
+
59
+ expect(actual_content).to match /"name": "app",/
60
+ end
61
+
62
+ it "creates webpack config directory and its files" do
63
+ expected_files = [
64
+ "webpack.config.js"
65
+ ]
66
+
67
+ Dir.chdir(path_in_the_app("config/webpack")) do
68
+ exisiting_files_in_config_webpack_dir = Dir.glob("*")
69
+ expect(exisiting_files_in_config_webpack_dir).to eq expected_files
70
+ end
71
+ end
72
+
73
+ it "adds binstubs" do
74
+ expected_binstubs = []
75
+ Dir.chdir(File.join(GEM_ROOT, "lib/install/bin")) do
76
+ expected_binstubs = Dir.glob("bin/*")
77
+ end
78
+
79
+ Dir.chdir(File.join(TEMP_RAILS_APP_PATH, "bin")) do
80
+ actual_binstubs = Dir.glob("*")
81
+ expect(actual_binstubs).to include(*expected_binstubs)
82
+ end
83
+ end
84
+
85
+ it "modifies .gitignore" do
86
+ actual_content = read(path_in_the_app(".gitignore"))
87
+
88
+ expect(actual_content).to match ".yarn-integrity"
89
+ end
90
+
91
+ it 'adds <%= javascript_pack_tag "application" %>' do
92
+ actual_content = read(path_in_the_app("app/views/layouts/application.html.erb"))
93
+
94
+ expect(actual_content).to match '<%= javascript_pack_tag "application" %>'
95
+ end
96
+
97
+ it "updates `bin/setup" do
98
+ setup_file_content = read(path_in_the_app("bin/setup"))
99
+ expect(setup_file_content).to match %r(^\s*system!\(['"]bin/yarn['"]\))
100
+ end
101
+
102
+ it "adds relevant shakapacker version in package.json depending on gem version," do
103
+ npm_version = Shakapacker::Utils::VersionSyntaxConverter.new.rubygem_to_npm(Shakapacker::VERSION)
104
+
105
+ actual_content = read(path_in_the_app("package.json"))
106
+
107
+ expect(actual_content).to match /"shakapacker": "#{npm_version}",/
108
+ end
109
+
110
+ it "adds Shakapacker peer dependencies to package.json" do
111
+ package_json = JSON.parse(File.read(path_in_the_app("package.json")))
112
+ actual_dependencies = package_json["dependencies"]&.keys
113
+
114
+ expected_dependencies = %w(
115
+ @babel/core
116
+ @babel/plugin-transform-runtime
117
+ @babel/preset-env
118
+ @babel/runtime
119
+ babel-loader
120
+ compression-webpack-plugin
121
+ terser-webpack-plugin
122
+ webpack
123
+ webpack-assets-manifest
124
+ webpack-cli
125
+ webpack-merge
126
+ )
127
+
128
+ expect(actual_dependencies).to include(*expected_dependencies)
129
+ end
130
+
131
+ it "adds Shakapacker peer dev dependencies to package.json" do
132
+ package_json = JSON.parse(File.read(path_in_the_app("package.json")))
133
+ actual_dev_dependencies = package_json["devDependencies"]&.keys
134
+
135
+ expected_dev_dependencies = %w(
136
+ webpack-dev-server
137
+ )
138
+
139
+ expect(actual_dev_dependencies).to include(*expected_dev_dependencies)
140
+ end
141
+
142
+ context "with a basic react app setup" do
143
+ it "passes the test for rendering react component on the page" do
144
+ Bundler.with_unbundled_env do
145
+ sh_in_dir(TEMP_RAILS_APP_PATH, "./bin/rails app:template LOCATION=../e2e_template/template.rb")
146
+ expect(sh_in_dir(TEMP_RAILS_APP_PATH, "bundle exec rspec")).to be_truthy
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ private
154
+ def path_in_the_app(relative_path = nil)
155
+ Pathname.new(File.join([TEMP_RAILS_APP_PATH, relative_path].compact))
156
+ end
157
+
158
+ def path_in_the_gem(relative_path = nil)
159
+ Pathname.new(File.join([GEM_ROOT, "lib/install" , relative_path].compact))
160
+ end
161
+
162
+ def read(path)
163
+ File.read(path)
164
+ end
165
+
166
+ def sh_in_dir(dir, *shell_commands)
167
+ Shakapacker::Utils::Misc.sh_in_dir(dir, *shell_commands)
168
+ end
169
+ end
@@ -1,7 +1,7 @@
1
1
  require_relative "spec_helper_initializer"
2
2
 
3
3
  describe "Shakapacker::Configuration" do
4
- ROOT_PATH = Pathname.new(File.expand_path("test_app", __dir__))
4
+ ROOT_PATH = Pathname.new(File.expand_path("./test_app", __dir__))
5
5
 
6
6
  context "with standard shakapacker.yml" do
7
7
  let(:config) do
@@ -13,37 +13,37 @@ describe "Shakapacker::Configuration" do
13
13
  end
14
14
 
15
15
  it "#source_path returns correct path" do
16
- source_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript").to_s
16
+ source_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript").to_s
17
17
  expect(config.source_path.to_s).to eq source_path
18
18
  end
19
19
 
20
20
  it "#source_entry_path returns correct path" do
21
- source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "entrypoints").to_s
21
+ source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "entrypoints").to_s
22
22
  expect(config.source_entry_path.to_s).to eq source_entry_path
23
23
  end
24
24
 
25
25
  it "#public_root_path returns correct path" do
26
- public_root_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public").to_s
26
+ public_root_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public").to_s
27
27
  expect(config.public_path.to_s).to eq public_root_path
28
28
  end
29
29
 
30
30
  it "#public_output_path returns correct path" do
31
- public_output_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs").to_s
31
+ public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs").to_s
32
32
  expect(config.public_output_path.to_s).to eq public_output_path
33
33
  end
34
34
 
35
35
  it "#public_manifest_path returns correct path" do
36
- public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
36
+ public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
37
37
  expect(config.public_manifest_path.to_s).to eq public_manifest_path
38
38
  end
39
39
 
40
40
  it "#manifest_path returns correct path" do
41
- manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s
41
+ manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
42
42
  expect(config.manifest_path.to_s).to eq manifest_path
43
43
  end
44
44
 
45
45
  it "#cache_path returns correct path" do
46
- cache_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/tmp/shakapacker").to_s
46
+ cache_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s
47
47
  expect(config.cache_path.to_s).to eq cache_path
48
48
  end
49
49
 
@@ -184,7 +184,7 @@ describe "Shakapacker::Configuration" do
184
184
  )
185
185
 
186
186
  it "#public_output_path returns correct path" do
187
- expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "public/packs").to_s
187
+ expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./public/packs").to_s
188
188
  expect(config.public_output_path.to_s).to eq expected_public_output_path
189
189
  end
190
190
  end
@@ -197,7 +197,7 @@ describe "Shakapacker::Configuration" do
197
197
  )
198
198
 
199
199
  it "#manifest_path returns correct expected value" do
200
- expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "test_app/app/javascript", "manifest.json").to_s
200
+ expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "manifest.json").to_s
201
201
  expect(config.manifest_path.to_s).to eq expected_manifest_path
202
202
  end
203
203
  end
@@ -14,7 +14,7 @@ describe "DevServerRunner" do
14
14
  ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
15
15
  end
16
16
 
17
- let(:test_app_path) { File.expand_path("test_app", __dir__) }
17
+ let(:test_app_path) { File.expand_path("./test_app", __dir__) }
18
18
 
19
19
  it "run cmd via node modules" do
20
20
  cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
@@ -21,7 +21,7 @@ describe "EngineRakeTasks" do
21
21
 
22
22
  private
23
23
  def mounted_app_path
24
- File.expand_path("mounted_app", __dir__)
24
+ File.expand_path("../mounted_app", __dir__)
25
25
  end
26
26
 
27
27
  def current_files_in_bin
@@ -29,7 +29,7 @@ describe "EngineRakeTasks" do
29
29
  end
30
30
 
31
31
  def expected_binstub_paths
32
- gem_path = File.expand_path("..", __dir__)
32
+ gem_path = File.expand_path("../..", __dir__)
33
33
  Dir.chdir("#{gem_path}/lib/install/bin") do
34
34
  Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
35
35
  end
@@ -1,7 +1,7 @@
1
1
  require_relative "spec_helper_initializer"
2
2
 
3
3
  describe "Shakapacker::Manifest" do
4
- let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "test_app/public/packs", "manifest.json").to_s }
4
+ let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s }
5
5
 
6
6
  it "#lookup! throws exception for a non-existing asset file" do
7
7
  asset_file = "calendar.js"
@@ -0,0 +1,93 @@
1
+ require_relative "spec_helper_initializer"
2
+
3
+ describe "RakeTasks" do
4
+ TEST_APP_PATH = File.expand_path("./test_app", __dir__)
5
+
6
+ it "`rake -T` lists Shakapacker tasks" do
7
+ output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
8
+ expect(output).to include "shakapacker"
9
+ expect(output).to include "shakapacker:check_binstubs"
10
+ expect(output).to include "shakapacker:check_node"
11
+ expect(output).to include "shakapacker:check_yarn"
12
+ expect(output).to include "shakapacker:clean"
13
+ expect(output).to include "shakapacker:clobber"
14
+ expect(output).to include "shakapacker:compile"
15
+ expect(output).to include "shakapacker:install"
16
+ expect(output).to include "shakapacker:verify_install"
17
+ end
18
+
19
+ it "`shakapacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
20
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_binstubs 2>&1` }
21
+ expect(output).to_not include "webpack binstub not found."
22
+ end
23
+
24
+ it "`shakapacker:check_node` doesn't get 'shakapacker requires Node.js' error" do
25
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_node 2>&1` }
26
+ expect(output).to_not include "Shakapacker requires Node.js"
27
+ end
28
+
29
+ it "`shakapacker:check_yarn` doesn't get error related to yarn" do
30
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_yarn 2>&1` }
31
+ expect(output).to_not include "Yarn not installed"
32
+ expect(output).to_not include "Shakapacker requires Yarn"
33
+ end
34
+
35
+ describe "`shakapacker:check_binstubs`" do
36
+ def with_temporary_file(file_name, &block)
37
+ FileUtils.touch(file_name, verbose: false)
38
+ yield if block_given?
39
+ ensure
40
+ FileUtils.rm_f(file_name, verbose: false)
41
+ end
42
+
43
+ before :all do
44
+ Dir.chdir(TEST_APP_PATH)
45
+ end
46
+
47
+ context "with existing `./bin/shapapacker` and `./bin/shapapacker-dev-server`" do
48
+ it "passes" do
49
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output("").to_stdout_from_any_process
50
+ end
51
+ end
52
+
53
+ context "without `./bin/shakapacker`" do
54
+ before :all do
55
+ FileUtils.mv("bin/shakapacker", "bin/shakapacker_renamed")
56
+ end
57
+
58
+ after :all do
59
+ FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
60
+ end
61
+
62
+ it "passes if `./bin/webpacker exist" do
63
+ with_temporary_file("bin/webpacker") do
64
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
65
+ end
66
+ end
67
+
68
+ it "fails otherwise" do
69
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
70
+ end
71
+ end
72
+
73
+ context "without `./bin/shakapacker-dev-server`" do
74
+ before :all do
75
+ FileUtils.mv("bin/shakapacker-dev-server", "bin/shakapacker-dev-server_renamed")
76
+ end
77
+
78
+ after :all do
79
+ FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
80
+ end
81
+
82
+ it "passes if `./bin/webpacker-dev-server exist" do
83
+ with_temporary_file("bin/webpacker-dev-server") do
84
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/DEPRECATION/).to_stdout_from_any_process
85
+ end
86
+ end
87
+
88
+ it "fails otherwise" do
89
+ expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
90
+ end
91
+ end
92
+ end
93
+ end
@@ -1,4 +1,4 @@
1
- require_relative "test_app/config/environment"
1
+ require_relative "./test_app/config/environment"
2
2
 
3
3
  Rails.env = "production"
4
4
 
File without changes
@@ -102,7 +102,7 @@ describe "VersionChecker::NodePackageVersion" do
102
102
  context "with no yarn.lock file" do
103
103
  def node_package_version(fixture_version:)
104
104
  Shakapacker::VersionChecker::NodePackageVersion.new(
105
- File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
105
+ File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
106
106
  "file/does/not/exist",
107
107
  "file/does/not/exist"
108
108
  )
@@ -272,8 +272,8 @@ describe "VersionChecker::NodePackageVersion" do
272
272
  context "with yarn.lock v1" do
273
273
  def node_package_version(fixture_version:)
274
274
  Shakapacker::VersionChecker::NodePackageVersion.new(
275
- File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
276
- File.expand_path("fixtures/#{fixture_version}_yarn.v1.lock", __dir__),
275
+ File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
276
+ File.expand_path("../fixtures/#{fixture_version}_yarn.v1.lock", __dir__),
277
277
  "file/does/not/exist"
278
278
  )
279
279
  end
@@ -442,8 +442,8 @@ describe "VersionChecker::NodePackageVersion" do
442
442
  context "with yarn.lock v2" do
443
443
  def node_package_version(fixture_version:)
444
444
  Shakapacker::VersionChecker::NodePackageVersion.new(
445
- File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
446
- File.expand_path("fixtures/#{fixture_version}_yarn.v2.lock", __dir__),
445
+ File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
446
+ File.expand_path("../fixtures/#{fixture_version}_yarn.v2.lock", __dir__),
447
447
  "file/does/not/exist"
448
448
  )
449
449
  end
@@ -612,9 +612,9 @@ describe "VersionChecker::NodePackageVersion" do
612
612
  context "with package-lock.json v1" do
613
613
  def node_package_version(fixture_version:)
614
614
  Shakapacker::VersionChecker::NodePackageVersion.new(
615
- File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
615
+ File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
616
616
  "file/does/not/exist",
617
- File.expand_path("fixtures/#{fixture_version}_package-lock.v1.json", __dir__),
617
+ File.expand_path("../fixtures/#{fixture_version}_package-lock.v1.json", __dir__),
618
618
  )
619
619
  end
620
620
 
@@ -782,9 +782,9 @@ describe "VersionChecker::NodePackageVersion" do
782
782
  context "with package-lock.json v2" do
783
783
  def node_package_version(fixture_version:)
784
784
  Shakapacker::VersionChecker::NodePackageVersion.new(
785
- File.expand_path("fixtures/#{fixture_version}_package.json", __dir__),
785
+ File.expand_path("../fixtures/#{fixture_version}_package.json", __dir__),
786
786
  "file/does/not/exist",
787
- File.expand_path("fixtures/#{fixture_version}_package-lock.v2.json", __dir__),
787
+ File.expand_path("../fixtures/#{fixture_version}_package-lock.v2.json", __dir__),
788
788
  )
789
789
  end
790
790
 
@@ -32,7 +32,7 @@ describe "WebpackRunner" do
32
32
 
33
33
  private
34
34
  def test_app_path
35
- File.expand_path("test_app", __dir__)
35
+ File.expand_path("./test_app", __dir__)
36
36
  end
37
37
 
38
38
  def verify_command(cmd, use_node_modules: true, argv: [])