Skip to content

Commit 894f415

Browse files
justin808claude
andcommitted
Add generator specs for --rspack option
Adds comprehensive test coverage for the --rspack generator option: ## New Test Contexts **with --rspack**: - Verifies base generator and non-redux generator behavior - Tests bin/switch-bundler script creation - Validates rspack dependencies in package.json - Ensures webpack dependencies are NOT installed - Checks unified webpack config with bundler detection - Verifies server webpack config uses bundler variable **with --rspack --typescript**: - Tests combination of rspack and typescript options - Verifies TypeScript component file creation (.tsx) - Validates tsconfig.json generation - Checks both rspack and typescript dependencies installed - Ensures TypeScript typing is correct ## Test Coverage 19 new examples added, all passing: - Dependency management (rspack vs webpack packages) - Webpack configuration templates (bundler detection) - TypeScript integration with rspack - bin/switch-bundler utility script ## Validation All specs pass successfully with 0 failures. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent cd5469f commit 894f415

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,99 @@
139139
end
140140
end
141141

142+
context "with --rspack" do
143+
before(:all) { run_generator_test_with_args(%w[--rspack], package_json: true) }
144+
145+
include_examples "base_generator", application_js: true
146+
include_examples "no_redux_generator"
147+
148+
it "creates bin/switch-bundler script" do
149+
assert_file "bin/switch-bundler" do |content|
150+
expect(content).to include("class BundlerSwitcher")
151+
expect(content).to include("RSPACK_DEPS")
152+
expect(content).to include("WEBPACK_DEPS")
153+
end
154+
end
155+
156+
it "installs rspack dependencies in package.json" do
157+
assert_file "package.json" do |content|
158+
package_json = JSON.parse(content)
159+
expect(package_json["dependencies"]).to include("@rspack/core")
160+
expect(package_json["dependencies"]).to include("rspack-manifest-plugin")
161+
expect(package_json["devDependencies"]).to include("@rspack/cli")
162+
expect(package_json["devDependencies"]).to include("@rspack/plugin-react-refresh")
163+
end
164+
end
165+
166+
it "does not install webpack-specific dependencies" do
167+
assert_file "package.json" do |content|
168+
package_json = JSON.parse(content)
169+
expect(package_json["dependencies"]).not_to include("webpack")
170+
expect(package_json["devDependencies"]).not_to include("webpack-cli")
171+
expect(package_json["devDependencies"]).not_to include("@pmmmwh/react-refresh-webpack-plugin")
172+
end
173+
end
174+
175+
it "generates unified webpack config with bundler detection" do
176+
assert_file "config/webpack/development.js" do |content|
177+
expect(content).to include("const { devServer, inliningCss, config } = require('shakapacker')")
178+
expect(content).to include("if (config.assets_bundler === 'rspack')")
179+
expect(content).to include("@rspack/plugin-react-refresh")
180+
expect(content).to include("@pmmmwh/react-refresh-webpack-plugin")
181+
end
182+
end
183+
184+
it "generates server webpack config with bundler variable" do
185+
assert_file "config/webpack/serverWebpackConfig.js" do |content|
186+
expect(content).to include("const bundler = config.assets_bundler === 'rspack'")
187+
expect(content).to include("? require('@rspack/core')")
188+
expect(content).to include(": require('webpack')")
189+
expect(content).to include("new bundler.optimize.LimitChunkCountPlugin")
190+
end
191+
end
192+
end
193+
194+
context "with --rspack --typescript" do
195+
before(:all) { run_generator_test_with_args(%w[--rspack --typescript], package_json: true) }
196+
197+
include_examples "base_generator_common", application_js: true
198+
include_examples "no_redux_generator"
199+
200+
it "creates TypeScript component files with .tsx extension" do
201+
assert_file "app/javascript/src/HelloWorld/ror_components/HelloWorld.client.tsx"
202+
assert_file "app/javascript/src/HelloWorld/ror_components/HelloWorld.server.tsx"
203+
end
204+
205+
it "creates tsconfig.json file" do
206+
assert_file "tsconfig.json" do |content|
207+
config = JSON.parse(content)
208+
expect(config["compilerOptions"]["jsx"]).to eq("react-jsx")
209+
expect(config["compilerOptions"]["strict"]).to be true
210+
expect(config["include"]).to include("app/javascript/**/*")
211+
end
212+
end
213+
214+
it "installs both rspack and typescript dependencies" do
215+
assert_file "package.json" do |content|
216+
package_json = JSON.parse(content)
217+
# Rspack dependencies
218+
expect(package_json["dependencies"]).to include("@rspack/core")
219+
expect(package_json["devDependencies"]).to include("@rspack/cli")
220+
# TypeScript dependencies
221+
expect(package_json["devDependencies"]).to include("typescript")
222+
expect(package_json["devDependencies"]).to include("@types/react")
223+
expect(package_json["devDependencies"]).to include("@types/react-dom")
224+
end
225+
end
226+
227+
it "TypeScript component includes proper typing" do
228+
assert_file "app/javascript/src/HelloWorld/ror_components/HelloWorld.client.tsx" do |content|
229+
expect(content).to match(/interface HelloWorldProps/)
230+
expect(content).to match(/React\.FC<HelloWorldProps>/)
231+
end
232+
end
233+
end
234+
142235
context "with helpful message" do
143236
let(:expected) do
144237
GeneratorMessages.format_info(GeneratorMessages.helpful_message_after_installation)

0 commit comments

Comments
 (0)