shakapacker 7.0.3 → 7.2.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dummy.yml +3 -1
  3. data/.github/workflows/generator.yml +6 -1
  4. data/.github/workflows/jest.yml +4 -2
  5. data/.github/workflows/js-lint.yml +4 -2
  6. data/.github/workflows/rubocop.yml +3 -1
  7. data/.github/workflows/ruby-backward-compatibility.yml +9 -1
  8. data/.github/workflows/ruby.yml +11 -2
  9. data/CHANGELOG.md +16 -3
  10. data/README.md +58 -23
  11. data/docs/troubleshooting.md +4 -8
  12. data/docs/using_esbuild_loader.md +2 -4
  13. data/docs/v6_upgrade.md +1 -1
  14. data/lib/install/template.rb +58 -18
  15. data/lib/shakapacker/compiler.rb +5 -3
  16. data/lib/shakapacker/configuration.rb +8 -0
  17. data/lib/shakapacker/deprecation_helper.rb +1 -1
  18. data/lib/shakapacker/dev_server_runner.rb +13 -6
  19. data/lib/shakapacker/runner.rb +19 -1
  20. data/lib/shakapacker/utils/misc.rb +12 -0
  21. data/lib/shakapacker/version.rb +1 -1
  22. data/lib/shakapacker/version_checker.rb +35 -2
  23. data/lib/shakapacker/webpack_runner.rb +16 -8
  24. data/lib/tasks/shakapacker/binstubs.rake +1 -1
  25. data/lib/tasks/shakapacker/check_manager.rake +27 -0
  26. data/lib/tasks/shakapacker/check_yarn.rake +2 -1
  27. data/lib/tasks/shakapacker/info.rake +20 -3
  28. data/lib/tasks/shakapacker/install.rake +1 -1
  29. data/lib/tasks/shakapacker/verify_install.rake +1 -1
  30. data/lib/tasks/shakapacker.rake +2 -2
  31. data/lib/tasks/webpacker/check_yarn.rake +1 -1
  32. data/package/__tests__/index.js +24 -0
  33. data/package/index.d.ts +1 -1
  34. data/package/index.js +8 -2
  35. data/package.json +2 -2
  36. data/shakapacker.gemspec +1 -0
  37. data/spec/backward_compatibility_specs/compiler_strategy_spec.rb +5 -3
  38. data/spec/backward_compatibility_specs/configuration_spec.rb +12 -4
  39. data/spec/backward_compatibility_specs/dev_server_runner_spec.rb +103 -42
  40. data/spec/backward_compatibility_specs/dev_server_spec.rb +1 -1
  41. data/spec/backward_compatibility_specs/digest_strategy_spec.rb +2 -0
  42. data/spec/backward_compatibility_specs/engine_rake_tasks_spec.rb +30 -7
  43. data/spec/backward_compatibility_specs/helper_spec.rb +20 -20
  44. data/spec/backward_compatibility_specs/instance_spec.rb +3 -3
  45. data/spec/backward_compatibility_specs/manifest_spec.rb +12 -12
  46. data/spec/backward_compatibility_specs/mtime_strategy_spec.rb +3 -3
  47. data/spec/backward_compatibility_specs/rake_tasks_spec.rb +9 -5
  48. data/spec/backward_compatibility_specs/webpack_runner_spec.rb +55 -25
  49. data/spec/dummy/config/webpack/commonWebpackConfig.js +1 -1
  50. data/spec/fixtures/beta_pnpm-lock.v7.yaml +116 -0
  51. data/spec/fixtures/beta_pnpm-lock.v8.yaml +2537 -0
  52. data/spec/fixtures/git_url_pnpm-lock.v7.yaml +126 -0
  53. data/spec/fixtures/git_url_pnpm-lock.v8.yaml +3728 -0
  54. data/spec/fixtures/github_url_pnpm-lock.v7.yaml +126 -0
  55. data/spec/fixtures/github_url_pnpm-lock.v8.yaml +3728 -0
  56. data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +18 -0
  57. data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +22 -0
  58. data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +117 -0
  59. data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +2558 -0
  60. data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +117 -0
  61. data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +2558 -0
  62. data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +116 -0
  63. data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +2558 -0
  64. data/spec/fixtures/without_pnpm-lock.v7.yaml +23 -0
  65. data/spec/fixtures/without_pnpm-lock.v8.yaml +27 -0
  66. data/spec/generator_specs/e2e_template/template.rb +31 -10
  67. data/spec/generator_specs/fake-bin/bun +10 -0
  68. data/spec/generator_specs/fake-bin/npm +10 -0
  69. data/spec/generator_specs/fake-bin/pnpm +10 -0
  70. data/spec/generator_specs/fake-bin/yarn +10 -0
  71. data/spec/generator_specs/generator_spec.rb +172 -18
  72. data/spec/mounted_app/package.json +1 -0
  73. data/spec/shakapacker/compiler_spec.rb +9 -5
  74. data/spec/shakapacker/compiler_strategy_spec.rb +5 -3
  75. data/spec/shakapacker/configuration_spec.rb +60 -2
  76. data/spec/shakapacker/dev_server_runner_spec.rb +108 -43
  77. data/spec/shakapacker/dev_server_spec.rb +1 -1
  78. data/spec/shakapacker/digest_strategy_spec.rb +2 -0
  79. data/spec/shakapacker/engine_rake_tasks_spec.rb +28 -6
  80. data/spec/shakapacker/helper_spec.rb +20 -20
  81. data/spec/shakapacker/instance_spec.rb +2 -2
  82. data/spec/shakapacker/manifest_spec.rb +12 -12
  83. data/spec/shakapacker/mtime_strategy_spec.rb +3 -3
  84. data/spec/shakapacker/rake_tasks_spec.rb +10 -6
  85. data/spec/shakapacker/shakapacker_spec.rb +4 -4
  86. data/spec/shakapacker/spec_helper_initializer.rb +18 -0
  87. data/spec/shakapacker/version_checker_spec.rb +468 -121
  88. data/spec/shakapacker/webpack_runner_spec.rb +55 -25
  89. data/spec/spec_helper.rb +2 -0
  90. data/spec/support/package_json_helpers.rb +16 -0
  91. metadata +42 -5
@@ -16,57 +16,122 @@ describe "DevServerRunner" do
16
16
 
17
17
  let(:test_app_path) { File.expand_path("./test_app", __dir__) }
18
18
 
19
- it "run cmd via node modules" do
20
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
21
- verify_command(cmd, use_node_modules: true)
22
- end
23
- it "run cmd via yarn" do
24
- cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
25
- verify_command(cmd, use_node_modules: false)
26
- end
27
- it "run cmd argv" do
28
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
29
- verify_command(cmd, argv: (["--quiet"]))
30
- end
31
- it "run cmd argv with https" do
32
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
33
-
34
- dev_server = double()
35
- allow(dev_server).to receive(:host).and_return("localhost")
36
- allow(dev_server).to receive(:port).and_return("3035")
37
- allow(dev_server).to receive(:pretty?).and_return(false)
38
- allow(dev_server).to receive(:https?).and_return(true)
39
- allow(dev_server).to receive(:hmr?).and_return(false)
40
-
41
- allow(Shakapacker::DevServer).to receive(:new) do
42
- verify_command(cmd, argv: (["--https"]))
43
- end.and_return(dev_server)
19
+ NODE_PACKAGE_MANAGERS.each do |fallback_manager|
20
+ context "when using package_json with #{fallback_manager} as the manager" do
21
+ with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
22
+
23
+ let(:package_json) { PackageJson.read(test_app_path) }
24
+
25
+ require "package_json"
26
+
27
+ it "uses the expected package manager", unless: fallback_manager == "yarn_classic" do
28
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
29
+
30
+ manager_name = fallback_manager.split("_")[0]
31
+
32
+ expect(cmd).to start_with(manager_name)
33
+ end
34
+
35
+ it "runs the command using the manager" do
36
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
37
+
38
+ verify_command(cmd)
39
+ end
40
+
41
+ it "passes on arguments" do
42
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"])
43
+
44
+ verify_command(cmd, argv: (["--quiet"]))
45
+ end
46
+
47
+ it "supports the https flag" do
48
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"])
49
+
50
+ dev_server = double()
51
+ allow(dev_server).to receive(:host).and_return("localhost")
52
+ allow(dev_server).to receive(:port).and_return("3035")
53
+ allow(dev_server).to receive(:pretty?).and_return(false)
54
+ allow(dev_server).to receive(:https?).and_return(true)
55
+ allow(dev_server).to receive(:hmr?).and_return(false)
56
+
57
+ allow(Shakapacker::DevServer).to receive(:new) do
58
+ verify_command(cmd, argv: (["--https"]))
59
+ end.and_return(dev_server)
60
+ end
61
+
62
+ it "accepts environment variables" do
63
+ cmd = package_json.manager.native_exec_command("webpack", ["serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"])
64
+
65
+ env = Shakapacker::Compiler.env.dup
66
+ ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
67
+ env["WEBPACK_SERVE"] = "true"
68
+
69
+ verify_command(cmd, env: env)
70
+ end
71
+ end
44
72
  end
45
- it "accepts environment variables" do
46
- cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
47
- env = Shakapacker::Compiler.env.dup
48
- ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
49
- env["WEBPACK_SERVE"] = "true"
50
- verify_command(cmd, env: env)
73
+
74
+ context "when not using package_json" do
75
+ with_use_package_json_gem(enabled: false)
76
+
77
+ it "supports running via node modules" do
78
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
79
+
80
+ verify_command(cmd, use_node_modules: true)
81
+ end
82
+
83
+ it "supports running via yarn" do
84
+ cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
85
+
86
+ verify_command(cmd, use_node_modules: false)
87
+ end
88
+
89
+ it "passes on arguments" do
90
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
91
+
92
+ verify_command(cmd, argv: (["--quiet"]))
93
+ end
94
+
95
+ it "supports the https flag" do
96
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
97
+
98
+ dev_server = double()
99
+ allow(dev_server).to receive(:host).and_return("localhost")
100
+ allow(dev_server).to receive(:port).and_return("3035")
101
+ allow(dev_server).to receive(:pretty?).and_return(false)
102
+ allow(dev_server).to receive(:https?).and_return(true)
103
+ allow(dev_server).to receive(:hmr?).and_return(false)
104
+
105
+ allow(Shakapacker::DevServer).to receive(:new) do
106
+ verify_command(cmd, argv: (["--https"]))
107
+ end.and_return(dev_server)
108
+ end
109
+
110
+ it "accepts environment variables" do
111
+ cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
112
+ env = Shakapacker::Compiler.env.dup
113
+
114
+ ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
115
+ env["WEBPACK_SERVE"] = "true"
116
+
117
+ verify_command(cmd, env: env)
118
+ end
51
119
  end
52
120
 
53
121
  private
54
122
 
55
123
  def verify_command(cmd, use_node_modules: true, argv: [], env: Shakapacker::Compiler.env)
56
- cwd = Dir.pwd
57
- Dir.chdir(test_app_path)
58
- klass = Shakapacker::DevServerRunner
59
- instance = klass.new(argv)
60
-
61
- allow(klass).to receive(:new).and_return(instance)
62
- allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
63
- allow(Kernel).to receive(:exec).with(env, *cmd)
124
+ Dir.chdir(test_app_path) do
125
+ klass = Shakapacker::DevServerRunner
126
+ instance = klass.new(argv)
64
127
 
65
- klass.run(argv)
128
+ allow(klass).to receive(:new).and_return(instance)
129
+ allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
130
+ allow(Kernel).to receive(:exec).with(env, *cmd)
66
131
 
67
- expect(Kernel).to have_received(:exec).with(env, *cmd)
132
+ klass.run(argv)
68
133
 
69
- ensure
70
- Dir.chdir(cwd)
134
+ expect(Kernel).to have_received(:exec).with(env, *cmd)
135
+ end
71
136
  end
72
137
  end
@@ -41,7 +41,7 @@ describe "DevServer" do
41
41
  end
42
42
  end
43
43
 
44
- it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
44
+ it "uses SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
45
45
  expect(Shakapacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
46
46
  end
47
47
 
@@ -23,6 +23,7 @@ describe "DigestStrategy" do
23
23
 
24
24
  it "is fresh after compilation" do
25
25
  @digest_strategy.after_compile_hook
26
+
26
27
  expect(@digest_strategy.stale?).to be false
27
28
  expect(@digest_strategy.fresh?).to be true
28
29
  end
@@ -30,6 +31,7 @@ describe "DigestStrategy" do
30
31
  it "generates correct compilation_digest_path" do
31
32
  actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
32
33
  expected_path = "last-compilation-digest-#{Shakapacker.env}"
34
+
33
35
  expect(actual_path).to eq expected_path
34
36
  end
35
37
  end
@@ -9,14 +9,36 @@ describe "EngineRakeTasks" do
9
9
  remove_webpack_binstubs
10
10
  end
11
11
 
12
- it "mounts app:shakapacker task successfully" do
13
- output = Dir.chdir(mounted_app_path) { `rake -T` }
14
- expect(output).to include "app:shakapacker"
12
+ NODE_PACKAGE_MANAGERS.each do |fallback_manager|
13
+ context "when using package_json with #{fallback_manager} as the manager" do
14
+ with_use_package_json_gem(enabled: true, fallback_manager: fallback_manager)
15
+
16
+ it "mounts app:shakapacker task successfully" do
17
+ output = Dir.chdir(mounted_app_path) { `rake -T` }
18
+
19
+ expect(output).to include "app:shakapacker"
20
+ end
21
+
22
+ it "only adds expected files to bin directory when binstubs is run" do
23
+ Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
24
+ expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
25
+ end
26
+ end
15
27
  end
16
28
 
17
- it "binstubs adds only expected files to bin directory" do
18
- Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
19
- expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
29
+ context "when not using package_json" do
30
+ with_use_package_json_gem(enabled: false)
31
+
32
+ it "mounts app:shakapacker task successfully" do
33
+ output = Dir.chdir(mounted_app_path) { `rake -T` }
34
+
35
+ expect(output).to include "app:shakapacker"
36
+ end
37
+
38
+ it "only adds expected files to bin directory when binstubs is run" do
39
+ Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
40
+ expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
41
+ end
20
42
  end
21
43
 
22
44
  private
@@ -22,17 +22,17 @@ module ActionView::TestCase::Behavior
22
22
  @javascript_pack_tag_loaded = nil
23
23
  end
24
24
 
25
- it "#asset_pack_path generates correct path" do
25
+ it "#asset_pack_path generates the correct path" do
26
26
  expect(asset_pack_path("bootstrap.js")).to eq "/packs/bootstrap-300631c4f0e0f9c865bc.js"
27
27
  expect(asset_pack_path("bootstrap.css")).to eq "/packs/bootstrap-c38deda30895059837cf.css"
28
28
  end
29
29
 
30
- it "#asset_pack_url generates correct url" do
30
+ it "#asset_pack_url generates the correct url" do
31
31
  expect(asset_pack_url("bootstrap.js")).to eq "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js"
32
32
  expect(asset_pack_url("bootstrap.css")).to eq "https://example.com/packs/bootstrap-c38deda30895059837cf.css"
33
33
  end
34
34
 
35
- it "#image_pack_path generates correct path" do
35
+ it "#image_pack_path generates the correct path" do
36
36
  expect(image_pack_path("application.png")).to eq "/packs/application-k344a6d59eef8632c9d1.png"
37
37
  expect(image_pack_path("image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
38
38
  expect(image_pack_path("static/image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
@@ -40,7 +40,7 @@ module ActionView::TestCase::Behavior
40
40
  expect(image_pack_path("static/nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
41
41
  end
42
42
 
43
- it "#image_pack_url generates correct path" do
43
+ it "#image_pack_url generates the correct path" do
44
44
  expect(image_pack_url("application.png")).to eq "https://example.com/packs/application-k344a6d59eef8632c9d1.png"
45
45
  expect(image_pack_url("image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
46
46
  expect(image_pack_url("static/image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
@@ -48,7 +48,7 @@ module ActionView::TestCase::Behavior
48
48
  expect(image_pack_url("static/nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
49
49
  end
50
50
 
51
- it "#image_pack_tag generates correct tags" do
51
+ it "#image_pack_tag generates the correct tags" do
52
52
  expect(image_pack_tag("application.png", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/application-k344a6d59eef8632c9d1.png\" width=\"16\" height=\"10\" />"
53
53
  expect(image_pack_tag("image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
54
54
  expect(image_pack_tag("static/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
@@ -57,7 +57,7 @@ module ActionView::TestCase::Behavior
57
57
  expect(image_pack_tag("static/image.jpg", srcset: { "static/image-2x.jpg" => "2x" })).to eq "<img srcset=\"/packs/static/image-2x-7cca48e6cae66ec07b8e.jpg 2x\" src=\"/packs/static/image-c38deda30895059837cf.jpg\" />"
58
58
  end
59
59
 
60
- it "#favicon_pack_tag generates correct tags" do
60
+ it "#favicon_pack_tag generates the correct tags" do
61
61
  expect(favicon_pack_tag("application.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/application-k344a6d59eef8632c9d1.png\" />"
62
62
  expect(favicon_pack_tag("mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />"
63
63
  expect(favicon_pack_tag("static/mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/mb-icon-c38deda30895059837cf.png\" />"
@@ -65,7 +65,7 @@ module ActionView::TestCase::Behavior
65
65
  expect(favicon_pack_tag("static/nested/mb-icon.png", rel: "apple-touch-icon", type: "image/png")).to eq "<link rel=\"apple-touch-icon\" type=\"image/png\" href=\"/packs/static/nested/mb-icon-c38deda30895059837cf.png\" />"
66
66
  end
67
67
 
68
- it "#preload_pack_asset generates correct tag" do
68
+ it "#preload_pack_asset generates the correct tag" do
69
69
  if self.class.method_defined?(:preload_link_tag)
70
70
  expect(preload_pack_asset("fonts/fa-regular-400.woff2")).to eq %(<link rel="preload" href="/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2" as="font" type="font/woff2" crossorigin="anonymous">)
71
71
  else
@@ -73,7 +73,7 @@ module ActionView::TestCase::Behavior
73
73
  end
74
74
  end
75
75
 
76
- it "#javascript_pack_tag generates correct tags" do
76
+ it "#javascript_pack_tag generates the correct tags" do
77
77
  expected = <<~HTML.chomp
78
78
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
79
79
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -84,7 +84,7 @@ module ActionView::TestCase::Behavior
84
84
  expect(javascript_pack_tag("application", "bootstrap")).to eq expected
85
85
  end
86
86
 
87
- it "#javascript_pack_tag generates correct tags by passing `defer: false`" do
87
+ it "#javascript_pack_tag generates the correct tags when passing `defer: false`" do
88
88
  expected = <<~HTML.chomp
89
89
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>
90
90
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>
@@ -95,7 +95,7 @@ module ActionView::TestCase::Behavior
95
95
  expect(javascript_pack_tag("application", "bootstrap", defer: false)).to eq expected
96
96
  end
97
97
 
98
- it "#javascript_pack_tag generates correct appended tag" do
98
+ it "#javascript_pack_tag generates the correct appended tag" do
99
99
  append_javascript_pack_tag("bootstrap", defer: false)
100
100
 
101
101
  expected = <<~HTML.chomp
@@ -108,7 +108,7 @@ module ActionView::TestCase::Behavior
108
108
  expect(javascript_pack_tag("application")).to eq expected
109
109
  end
110
110
 
111
- it "#javascript_pack_tag generates correct prepended tag" do
111
+ it "#javascript_pack_tag generates the correct prepended tag" do
112
112
  append_javascript_pack_tag("bootstrap")
113
113
  prepend_javascript_pack_tag("main")
114
114
 
@@ -123,7 +123,7 @@ module ActionView::TestCase::Behavior
123
123
  expect(javascript_pack_tag("application")).to eq expected
124
124
  end
125
125
 
126
- it "#append_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
126
+ it "#append_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
127
127
  expected_error_message = \
128
128
  "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
129
129
  "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
@@ -134,7 +134,7 @@ module ActionView::TestCase::Behavior
134
134
  }.to raise_error(expected_error_message)
135
135
  end
136
136
 
137
- it "#prepend_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
137
+ it "#prepend_javascript_pack_tag raises an error if called after calling #javascript_pack_tag" do
138
138
  expected_error_message = \
139
139
  "You can only call prepend_javascript_pack_tag before javascript_pack_tag helper. " +
140
140
  "Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-prepend_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
@@ -145,7 +145,7 @@ module ActionView::TestCase::Behavior
145
145
  }.to raise_error(expected_error_message)
146
146
  end
147
147
 
148
- it "#javascript_pack_tag generates correct tags by passing `defer: true`" do
148
+ it "#javascript_pack_tag generates the correct tags when passing `defer: true`" do
149
149
  expected = <<~HTML.chomp
150
150
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
151
151
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -155,7 +155,7 @@ module ActionView::TestCase::Behavior
155
155
  expect(javascript_pack_tag("application", defer: true)).to eq expected
156
156
  end
157
157
 
158
- it "#javascript_pack_tag generates correct tags by passing symbol" do
158
+ it "#javascript_pack_tag generates the correct tags when passing a symbol" do
159
159
  expected = <<~HTML.chomp
160
160
  <script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
161
161
  <script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
@@ -175,7 +175,7 @@ module ActionView::TestCase::Behavior
175
175
  }.to raise_error(expected_error_message)
176
176
  end
177
177
 
178
- it "#stylesheet_pack_tag generates correct link tag with string arguments" do
178
+ it "#stylesheet_pack_tag generates the correct link tag with string arguments" do
179
179
  expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
180
180
  .uniq
181
181
  .map { |chunk| stylesheet_link_tag(chunk) }
@@ -184,7 +184,7 @@ module ActionView::TestCase::Behavior
184
184
  expect(stylesheet_pack_tag("application", "hello_stimulus")).to eq expected
185
185
  end
186
186
 
187
- it "#stylesheet_pack_tag generates correct link tag with symbol arguments" do
187
+ it "#stylesheet_pack_tag generates the correct link tag with symbol arguments" do
188
188
  expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
189
189
  .uniq
190
190
  .map { |chunk| stylesheet_link_tag(chunk) }
@@ -193,7 +193,7 @@ module ActionView::TestCase::Behavior
193
193
  expect(stylesheet_pack_tag(:application, :hello_stimulus)).to eq expected
194
194
  end
195
195
 
196
- it "#stylesheet_pack_tag generates correct link tag with mixed arguments" do
196
+ it "#stylesheet_pack_tag generates the correct link tag with mixed arguments" do
197
197
  expected = (application_stylesheet_chunks)
198
198
  .map { |chunk| stylesheet_link_tag(chunk, media: "all") }
199
199
  .join("\n")
@@ -215,7 +215,7 @@ module ActionView::TestCase::Behavior
215
215
  }.to_not raise_error
216
216
  end
217
217
 
218
- it "#stylesheet_pack_tag appends" do
218
+ it "#stylesheet_pack_tag appends tags" do
219
219
  append_stylesheet_pack_tag(:hello_stimulus)
220
220
 
221
221
  expect(stylesheet_pack_tag(:application)).to eq \
@@ -230,7 +230,7 @@ module ActionView::TestCase::Behavior
230
230
  (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
231
231
  end
232
232
 
233
- it "#stylesheet_pack_tag supports multiple invocations with different media attr" do
233
+ it "#stylesheet_pack_tag supports multiple invocations with different media attr values" do
234
234
  app_style = stylesheet_pack_tag(:application)
235
235
  app_style_with_media = stylesheet_pack_tag(:application, media: "print")
236
236
  hello_stimulus_style_with_media = stylesheet_pack_tag(:hello_stimulus, media: "all")
@@ -13,14 +13,14 @@ describe "Shakapacker::Instance" do
13
13
  Shakapacker.instance = Shakapacker::Instance.new
14
14
  end
15
15
 
16
- it "uses default config path if no env variable defined" do
16
+ it "uses the default config path if no env variable defined" do
17
17
  actual_config_path = Rails.root.join("config/shakapacker.yml")
18
18
  expected_config_path = Shakapacker.config.config_path
19
19
 
20
20
  expect(expected_config_path).to eq(actual_config_path)
21
21
  end
22
22
 
23
- it "uses SHAKAPACKER_CONFIG env variable for config file" do
23
+ it "uses the SHAKAPACKER_CONFIG env variable for the config file path" do
24
24
  ENV["SHAKAPACKER_CONFIG"] = "/some/random/path.yml"
25
25
 
26
26
  actual_config_path = "/some/random/path.yml"
@@ -3,7 +3,7 @@ require_relative "spec_helper_initializer"
3
3
  describe "Shakapacker::Manifest" do
4
4
  let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s }
5
5
 
6
- it "#lookup! throws exception for a non-existing asset file" do
6
+ it "#lookup! raises an exception for a non-existing asset file" do
7
7
  asset_file = "calendar.js"
8
8
  expected_error_message = "Shakapacker can't find #{asset_file} in #{manifest_path}"
9
9
 
@@ -14,7 +14,7 @@ describe "Shakapacker::Manifest" do
14
14
  }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
15
15
  end
16
16
 
17
- it "#lookup! throws exception for a non-existing asset file with type and without extension" do
17
+ it "#lookup! raises an exception for a non-existing asset file with type and without an extension" do
18
18
  asset_file = "calendar"
19
19
  expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
20
20
 
@@ -25,57 +25,57 @@ describe "Shakapacker::Manifest" do
25
25
  }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
26
26
  end
27
27
 
28
- it "#lookup! returns path to bundled bootstrap.js" do
28
+ it "#lookup! returns the path to the bundled bootstrap.js" do
29
29
  actual = Shakapacker.manifest.lookup!("bootstrap.js")
30
30
  expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
31
31
 
32
32
  expect(actual).to eq expected
33
33
  end
34
34
 
35
- it "#lookup_pack_with_chunks! returns array of path to bundled bootstrap with type of javascript" do
35
+ it "#lookup_pack_with_chunks! returns an array of paths to the bundled bootstrap of type javascript" do
36
36
  actual = Shakapacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
37
37
  expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
38
38
 
39
39
  expect(actual).to eq expected
40
40
  end
41
41
 
42
- it "#lookup_with_chunks! returns array of path to bundled bootstrap.js with type of javascript" do
42
+ it "#lookup_with_chunks! returns an array of paths to the bundled bootstrap.js of type javascript" do
43
43
  actual = Shakapacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
44
44
  expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
45
45
 
46
46
  expect(actual).to eq expected
47
47
  end
48
48
 
49
- it "#lookup_with_chunks! returns array of path to bundled 'print/application' without extension and in a sub-directory" do
49
+ it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application' without an extension and in a sub-directory" do
50
50
  actual = Shakapacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
51
51
  expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
52
52
 
53
53
  expect(actual).to eq expected
54
54
  end
55
55
 
56
- it "#lookup_with_chunks! returns array of path to bundled 'print/application.css' in a sub-directory" do
56
+ it "#lookup_with_chunks! returns an array of paths to the bundled 'print/application.css' in a sub-directory" do
57
57
  actual = Shakapacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
58
58
  expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
59
59
 
60
60
  expect(actual).to eq expected
61
61
  end
62
62
 
63
- it "#lookup returns nil for non-existing asset file" do
63
+ it "#lookup returns nil for non-existing asset files" do
64
64
  expect(Shakapacker.manifest.lookup("foo.js")).to be nil
65
65
  end
66
66
 
67
- it "#lookup_pack_with_chunks returns nil for non-existing asset file" do
67
+ it "#lookup_pack_with_chunks returns nil for non-existing asset files" do
68
68
  expect(Shakapacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
69
69
  end
70
70
 
71
- it "#lookup returns path for bootstrap.js" do
71
+ it "#lookup returns the path for bootstrap.js" do
72
72
  actual = Shakapacker.manifest.lookup("bootstrap.js")
73
73
  expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
74
74
 
75
75
  expect(actual).to eq expected
76
76
  end
77
77
 
78
- it "#lookup_pack_with_chunks! throws exception for a non-existing asset file" do
78
+ it "#lookup_pack_with_chunks! raises an exception for non-existing asset files" do
79
79
  asset_file = "calendar"
80
80
 
81
81
  expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
@@ -87,7 +87,7 @@ describe "Shakapacker::Manifest" do
87
87
  }.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
88
88
  end
89
89
 
90
- it "#lookup_pack_with_chunks! returns array of paths to bundled js files with 'application' in their name" do
90
+ it "#lookup_pack_with_chunks! returns an array of paths to bundled js files with 'application' in their name" do
91
91
  actual_application_entrypoints = Shakapacker.manifest.lookup_pack_with_chunks!("application", type: :javascript)
92
92
  expected_application_entrypoints = [
93
93
  "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
@@ -5,7 +5,7 @@ describe "Shakapacker::MtimeStrategy" do
5
5
  let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }
6
6
 
7
7
  describe "#fresh?" do
8
- it "returns false when manifest is missing" do
8
+ it "returns false when the manifest is missing" do
9
9
  latest_timestamp = manifest_timestamp + 3600
10
10
 
11
11
  with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
@@ -13,7 +13,7 @@ describe "Shakapacker::MtimeStrategy" do
13
13
  end
14
14
  end
15
15
 
16
- it "returns false when manifest is older" do
16
+ it "returns false when the manifest is older" do
17
17
  latest_timestamp = manifest_timestamp + 3600
18
18
 
19
19
  with_stubs(latest_timestamp: latest_timestamp.to_i) do
@@ -21,7 +21,7 @@ describe "Shakapacker::MtimeStrategy" do
21
21
  end
22
22
  end
23
23
 
24
- it "returns true when manifest is new" do
24
+ it "returns true when the manifest is new" do
25
25
  latest_timestamp = manifest_timestamp - 3600
26
26
 
27
27
  with_stubs(latest_timestamp: latest_timestamp.to_i) do
@@ -8,7 +8,7 @@ describe "RakeTasks" do
8
8
  expect(output).to include "shakapacker"
9
9
  expect(output).to include "shakapacker:check_binstubs"
10
10
  expect(output).to include "shakapacker:check_node"
11
- expect(output).to include "shakapacker:check_yarn"
11
+ expect(output).to include "shakapacker:check_manager"
12
12
  expect(output).to include "shakapacker:clean"
13
13
  expect(output).to include "shakapacker:clobber"
14
14
  expect(output).to include "shakapacker:compile"
@@ -18,22 +18,26 @@ describe "RakeTasks" do
18
18
 
19
19
  it "`shakapacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
20
20
  output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_binstubs 2>&1` }
21
+
21
22
  expect(output).to_not include "webpack binstub not found."
22
23
  end
23
24
 
24
25
  it "`shakapacker:check_node` doesn't get 'shakapacker requires Node.js' error" do
25
26
  output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_node 2>&1` }
27
+
26
28
  expect(output).to_not include "Shakapacker requires Node.js"
27
29
  end
28
30
 
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"
31
+ # TODO: currently this test depends on external conditions & PACKAGE_JSON_FALLBACK_MANAGER
32
+ it "`shakapacker:check_manager` doesn't get errors related to the package manager" do
33
+ output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_manager 2>&1` }
34
+
35
+ expect(output).to_not include "not installed"
36
+ expect(output).to_not include "Shakapacker requires"
33
37
  end
34
38
 
35
39
  describe "`shakapacker:check_binstubs`" do
36
- def with_temporary_file(file_name, &block)
40
+ def with_temporary_file(file_name)
37
41
  FileUtils.touch(file_name, verbose: false)
38
42
  yield if block_given?
39
43
  ensure
@@ -12,11 +12,11 @@ describe "Shakapacker" do
12
12
  allow(dev_server).to receive(:running?).and_return(true)
13
13
  end
14
14
 
15
- it "returns nil with disabled dev_server" do
15
+ it "returns nil when the dev server is disabled" do
16
16
  expect(Shakapacker.inlining_css?).to be nil
17
17
  end
18
18
 
19
- it "returns true with enabled hmr" do
19
+ it "returns true when hmr is enabled" do
20
20
  allow(dev_server).to receive(:hmr?).and_return(true)
21
21
  allow(dev_server).to receive(:inline_css?).and_return(true)
22
22
 
@@ -25,7 +25,7 @@ describe "Shakapacker" do
25
25
  expect(Shakapacker.inlining_css?).to be true
26
26
  end
27
27
 
28
- it "returns false with enabled hmr and explicitly setting inline_css to false" do
28
+ it "returns false when hmr is enabled and inline_css is explicitly set to false" do
29
29
  allow(dev_server).to receive(:hmr?).and_return(true)
30
30
  allow(dev_server).to receive(:inline_css?).and_return(false)
31
31
 
@@ -35,7 +35,7 @@ describe "Shakapacker" do
35
35
  end
36
36
  end
37
37
 
38
- it "has app_autoload_paths cleanup" do
38
+ it "automatically cleans up app_autoload_paths" do
39
39
  expect($test_app_autoload_paths_in_initializer).to eq []
40
40
  end
41
41
  end
@@ -22,3 +22,21 @@ ensure
22
22
  Rails.env = ActiveSupport::StringInquirer.new(original)
23
23
  reloaded_config
24
24
  end
25
+
26
+ # Temportarily set env variables to a custom value
27
+ # arg: a hash with key:value for each custom env
28
+ # Keys could be string or symbol
29
+ def with_env_variable(custom_env_hash)
30
+ original_env = {}
31
+ custom_env_hash.each do |key, new_value|
32
+ upcased_key = key.to_s.upcase
33
+ original_env[upcased_key] = new_value
34
+ ENV[upcased_key] = new_value
35
+ end
36
+
37
+ yield
38
+ ensure
39
+ original_env.each do |key, original_value|
40
+ ENV[key] = original_value
41
+ end
42
+ end