Skip to content

Commit 880fa24

Browse files
alexeyr-cialexeyrJudahmeek
committed
Fix generator tests (#1706)
* Allow for different shakapacker versions in convert script * Fix the generator tests --------- Co-authored-by: Alexey Romanov <[email protected]> Co-authored-by: Judah Meek <[email protected]>
1 parent fe0b677 commit 880fa24

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

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,13 +13,13 @@ 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

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

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

0 commit comments

Comments
 (0)