Skip to content

Commit e28e56a

Browse files
alexeyr-cialexeyrJudahmeek
authored
Fix generator tests (#1706)
* Allow for different shakapacker versions in convert script * Fix the generator tests --------- Co-authored-by: Alexey Romanov <alexey.v.romanov@gmail.com> Co-authored-by: Judah Meek <judah.meek@gmail.com>
1 parent a877c76 commit e28e56a

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ yalc add react-on-rails
228228

229229
### Testing the Generator
230230

231-
The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator_testing_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project.
231+
The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator-testing.md](docs/contributor-info/generator-testing.md) for a script on how to run the generator on a fresh project.
232232

233-
`rake run_rspec:example_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:examples`. Be aware that this will create a hug number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done.
233+
`rake run_rspec:shakapacker_examples_basic` is a great way to run tests on one generator. Once that works, you should run `rake run_rspec:shakapacker_examples`. Be aware that this will create a huge number of files under a `/gen-examples` directory. You should be sure to exclude this directory from your IDE and delete it once your testing is done.
234234

235235
### Linting
236236

lib/generators/react_on_rails/dev_tests_generator.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ def replace_prerender_if_server_rendering
4747

4848
def add_yarn_relative_install_script_in_package_json
4949
package_json = File.join(destination_root, "package.json")
50-
contents = File.read(package_json)
51-
replacement_value = <<-STRING
52-
"scripts": {
53-
"postinstall": "yalc link react-on-rails",
54-
STRING
55-
new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
56-
replacement_value)
57-
File.open(package_json, "w+") { |f| f.puts new_client_package_json_contents }
50+
contents = JSON.parse(File.read(package_json))
51+
contents["scripts"] ||= {}
52+
contents["scripts"]["postinstall"] = "yalc link react-on-rails"
53+
File.open(package_json, "w+") { |f| f.puts JSON.pretty_generate(contents) }
5854
end
5955
end
6056
end

script/convert

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ new_config = File.expand_path("../spec/dummy/config/webpacker.yml", __dir__)
1313

1414
File.rename(old_config, new_config)
1515

16-
gsub_file_content("../Gemfile.development_dependencies", 'gem "shakapacker", "8.0.0"', 'gem "shakapacker", "6.6.0"')
16+
gsub_file_content("../Gemfile.development_dependencies", /gem "shakapacker", "[^"]*"/, 'gem "shakapacker", "6.6.0"')
1717

1818
# The below packages don't work on the oldest supported Node version and aren't needed there anyway
1919
gsub_file_content("../package.json", /"knip": "[^"]*",/, "")
2020
gsub_file_content("../package.json", %r{"@arethetypeswrong/cli": "[^"]*",}, "")
2121
gsub_file_content("../package.json", %r{"@testing-library/dom": "[^"]*",}, "")
2222
gsub_file_content("../package.json", %r{"@testing-library/react": "[^"]*",}, "")
2323

24-
gsub_file_content("../spec/dummy/package.json", '"shakapacker": "8.0.0",', '"shakapacker": "6.6.0",')
24+
gsub_file_content("../spec/dummy/package.json", /"shakapacker": "[^"]*",/, '"shakapacker": "6.6.0",')
2525

2626
gsub_file_content("../spec/dummy/config/webpack/commonWebpackConfig.js", /generateWebpackConfig(\(\))?/,
2727
"webpackConfig")

0 commit comments

Comments
 (0)