shakapacker 6.5.5 → 6.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +11 -7
- data/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
- data/.github/workflows/ruby.yml +3 -1
- data/.gitignore +3 -3
- data/.rspec +1 -0
- data/CHANGELOG.md +18 -2
- data/CONTRIBUTING.md +11 -1
- data/Gemfile.development_dependencies +3 -1
- data/README.md +41 -8
- data/Rakefile +4 -5
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.5.2.x +1 -1
- data/gemfiles/Gemfile-rails.6.0.x +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +1 -1
- data/gemfiles/Gemfile-rails.7.0.x +1 -1
- data/lib/install/template.rb +21 -16
- data/lib/tasks/webpacker/compile.rake +5 -10
- data/lib/webpacker/helper.rb +20 -9
- data/lib/webpacker/version.rb +1 -1
- data/package/rules/__tests__/__utils__/webpack.js +50 -0
- data/package/rules/__tests__/babel.js +63 -0
- data/package/rules/__tests__/esbuild.js +64 -0
- data/package/rules/__tests__/index.js +0 -4
- data/package/rules/__tests__/swc.js +64 -0
- data/package/rules/babel.js +3 -14
- data/package/rules/esbuild.js +2 -13
- data/package/rules/jscommon.js +26 -0
- data/package/rules/swc.js +2 -13
- data/package/utils/helpers.js +1 -1
- data/package.json +8 -2
- data/spec/command_spec.rb +114 -0
- data/spec/compiler_spec.rb +57 -0
- data/spec/compiler_strategy_spec.rb +20 -0
- data/spec/configuration_spec.rb +281 -0
- data/{test/dev_server_runner_test.rb → spec/dev_server_runner_spec.rb} +30 -40
- data/spec/dev_server_spec.rb +45 -0
- data/spec/digest_strategy_spec.rb +33 -0
- data/{test/engine_rake_tasks_test.rb → spec/engine_rake_tasks_spec.rb} +17 -9
- data/spec/env_spec.rb +21 -0
- data/{test → spec}/fixtures/beta_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/beta_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/beta_package.json +0 -0
- data/{test → spec}/fixtures/beta_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/beta_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/git_url_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/git_url_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/git_url_package.json +0 -0
- data/{test → spec}/fixtures/git_url_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/git_url_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/github_url_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/github_url_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/github_url_package.json +0 -0
- data/{test → spec}/fixtures/github_url_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/github_url_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/relative_path_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/relative_path_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/relative_path_package.json +0 -0
- data/{test → spec}/fixtures/relative_path_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/relative_path_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_caret_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_caret_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_caret_package.json +0 -0
- data/{test → spec}/fixtures/semver_caret_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_caret_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_exact_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_exact_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_exact_package.json +0 -0
- data/{test → spec}/fixtures/semver_exact_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_exact_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/semver_tilde_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_package.json +0 -0
- data/{test → spec}/fixtures/semver_tilde_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/semver_tilde_yarn.v2.lock +0 -0
- data/{test → spec}/fixtures/without_package-lock.v1.json +0 -0
- data/{test → spec}/fixtures/without_package-lock.v2.json +0 -0
- data/{test → spec}/fixtures/without_package.json +0 -0
- data/{test → spec}/fixtures/without_yarn.v1.lock +0 -0
- data/{test → spec}/fixtures/without_yarn.v2.lock +0 -0
- data/spec/helper_spec.rb +241 -0
- data/spec/manifest_spec.rb +98 -0
- data/{test → spec}/mounted_app/Rakefile +0 -0
- data/{test → spec}/mounted_app/test/dummy/Rakefile +0 -0
- data/{test → spec}/mounted_app/test/dummy/bin/rails +0 -0
- data/{test → spec}/mounted_app/test/dummy/bin/rake +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/application.rb +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/environment.rb +0 -0
- data/{test → spec}/mounted_app/test/dummy/config/webpacker.yml +0 -0
- data/{test → spec}/mounted_app/test/dummy/config.ru +0 -0
- data/{test → spec}/mounted_app/test/dummy/package.json +0 -0
- data/spec/mtime_strategy_spec.rb +53 -0
- data/spec/rake_tasks_spec.rb +32 -0
- data/spec/spec_helper.rb +123 -0
- data/{test → spec}/test_app/Rakefile +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/application.js +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/generated/something.js +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.css +0 -0
- data/{test → spec}/test_app/app/packs/entrypoints/multi_entry.js +0 -0
- data/{test → spec}/test_app/bin/webpacker +0 -0
- data/{test → spec}/test_app/bin/webpacker-dev-server +0 -0
- data/{test → spec}/test_app/config/application.rb +0 -0
- data/{test → spec}/test_app/config/environment.rb +0 -0
- data/{test → spec}/test_app/config/initializers/inspect_autoload_paths.rb +0 -0
- data/{test → spec}/test_app/config/webpack/webpack.config.js +0 -0
- data/{test → spec}/test_app/config/webpacker.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_css_extract_ignore_order_warnings.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_defaults_fallback.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_manifest_path.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_nested_entries.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_no_precompile.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_other_location.yml +0 -0
- data/{test → spec}/test_app/config/webpacker_public_root.yml +0 -0
- data/{test → spec}/test_app/config.ru +0 -0
- data/{test → spec}/test_app/package.json +0 -0
- data/{test → spec}/test_app/public/packs/manifest.json +8 -0
- data/{test → spec}/test_app/some.config.js +0 -0
- data/{test → spec}/test_app/yarn.lock +0 -0
- data/spec/version_checker_spec.rb +950 -0
- data/{test/webpack_runner_test.rb → spec/webpack_runner_spec.rb} +12 -15
- data/spec/webpacker_spec.rb +39 -0
- data/yarn.lock +846 -844
- metadata +102 -187
- data/.github/ISSUE_TEMPLATE/feature-request.md +0 -18
- data/lib/tasks/yarn.rake +0 -44
- data/test/command_test.rb +0 -109
- data/test/compiler_strategy_test.rb +0 -27
- data/test/compiler_test.rb +0 -60
- data/test/configuration_test.rb +0 -186
- data/test/dev_server_test.rb +0 -47
- data/test/digest_strategy_test.rb +0 -33
- data/test/env_test.rb +0 -23
- data/test/helper_test.rb +0 -248
- data/test/manifest_test.rb +0 -89
- data/test/mtime_strategy_test.rb +0 -42
- data/test/rake_tasks_test.rb +0 -37
- data/test/test_helper.rb +0 -33
- data/test/version_checker_test.rb +0 -826
- data/test/webpacker_test.rb +0 -49
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
1
|
require "webpacker/dev_server_runner"
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
describe "DevServerRunner" do
|
|
4
|
+
before do
|
|
6
5
|
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
|
7
6
|
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
|
8
7
|
@original_webpacker_config = ENV["WEBPACKER_CONFIG"]
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
after do
|
|
12
11
|
ENV["NODE_ENV"] = @original_node_env
|
|
13
12
|
ENV["RAILS_ENV"] = @original_rails_env
|
|
14
13
|
ENV["WEBPACKER_CONFIG"] = @original_webpacker_config
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
|
16
|
+
let(:test_app_path) { File.expand_path("test_app", __dir__) }
|
|
19
17
|
|
|
18
|
+
it "run cmd via node modules" do
|
|
19
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
|
20
20
|
verify_command(cmd, use_node_modules: true)
|
|
21
21
|
end
|
|
22
|
-
|
|
23
|
-
def test_run_cmd_via_yarn
|
|
22
|
+
it "run cmd via yarn" do
|
|
24
23
|
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
|
25
|
-
|
|
26
24
|
verify_command(cmd, use_node_modules: false)
|
|
27
25
|
end
|
|
28
|
-
|
|
29
|
-
def test_run_cmd_argv
|
|
26
|
+
it "run cmd argv" do
|
|
30
27
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
|
|
31
|
-
|
|
32
|
-
verify_command(cmd, argv: ["--quiet"])
|
|
28
|
+
verify_command(cmd, argv: (["--quiet"]))
|
|
33
29
|
end
|
|
34
|
-
|
|
35
|
-
def test_run_cmd_argv_with_https
|
|
30
|
+
it "run cmd argv with https" do
|
|
36
31
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
|
|
37
32
|
|
|
38
|
-
dev_server =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
Webpacker::DevServer.stub(:new, dev_server) do
|
|
45
|
-
verify_command(cmd, argv: ["--https"])
|
|
46
|
-
end
|
|
47
|
-
end
|
|
33
|
+
dev_server = double()
|
|
34
|
+
allow(dev_server).to receive(:host).and_return("localhost")
|
|
35
|
+
allow(dev_server).to receive(:port).and_return("3035")
|
|
36
|
+
allow(dev_server).to receive(:pretty?).and_return(false)
|
|
37
|
+
allow(dev_server).to receive(:https?).and_return(true)
|
|
38
|
+
allow(dev_server).to receive(:hmr?).and_return(false)
|
|
48
39
|
|
|
49
|
-
|
|
40
|
+
allow(Webpacker::DevServer).to receive(:new) do
|
|
41
|
+
verify_command(cmd, argv: (["--https"]))
|
|
42
|
+
end.and_return(dev_server)
|
|
43
|
+
end
|
|
44
|
+
it "accepts environment variables" do
|
|
50
45
|
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
|
51
46
|
env = Webpacker::Compiler.env.dup
|
|
52
47
|
ENV["WEBPACKER_CONFIG"] = env["WEBPACKER_CONFIG"] = "#{test_app_path}/config/webpacker_other_location.yml"
|
|
@@ -55,27 +50,22 @@ class DevServerRunnerTest < Webpacker::Test
|
|
|
55
50
|
end
|
|
56
51
|
|
|
57
52
|
private
|
|
58
|
-
def test_app_path
|
|
59
|
-
File.expand_path("test_app", __dir__)
|
|
60
|
-
end
|
|
61
53
|
|
|
62
54
|
def verify_command(cmd, use_node_modules: true, argv: [], env: Webpacker::Compiler.env)
|
|
63
55
|
cwd = Dir.pwd
|
|
64
56
|
Dir.chdir(test_app_path)
|
|
65
|
-
|
|
66
57
|
klass = Webpacker::DevServerRunner
|
|
67
58
|
instance = klass.new(argv)
|
|
68
|
-
mock = Minitest::Mock.new
|
|
69
|
-
mock.expect(:call, nil, [env, *cmd])
|
|
70
59
|
|
|
71
|
-
klass.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
allow(klass).to receive(:new).and_return(instance)
|
|
61
|
+
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
|
62
|
+
allow(Kernel).to receive(:exec).with(env, *cmd)
|
|
63
|
+
|
|
64
|
+
klass.run(argv)
|
|
65
|
+
|
|
66
|
+
expect(Kernel).to have_received(:exec).with(env, *cmd)
|
|
76
67
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
Dir.chdir(cwd)
|
|
68
|
+
ensure
|
|
69
|
+
Dir.chdir(cwd)
|
|
80
70
|
end
|
|
81
71
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
describe "DevServer" do
|
|
2
|
+
it "doesn't run by default" do
|
|
3
|
+
expect(Webpacker.dev_server.running?).to be_falsy
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "uses localhost as host in development environment" do
|
|
7
|
+
with_rails_env("development") do
|
|
8
|
+
expect(Webpacker.dev_server.host).to eq "localhost"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "uses port 3035 in development environment" do
|
|
13
|
+
with_rails_env("development") do
|
|
14
|
+
expect(Webpacker.dev_server.port).to eq 3035
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "doesn't use https in development environment" do
|
|
19
|
+
with_rails_env("development") do
|
|
20
|
+
expect(Webpacker.dev_server.https?).to be false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "uses http protocol in development environment" do
|
|
25
|
+
with_rails_env("development") do
|
|
26
|
+
expect(Webpacker.dev_server.protocol).to eq "http"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "sets host_with_port to localhost:3035 in development environment" do
|
|
31
|
+
with_rails_env("development") do
|
|
32
|
+
expect(Webpacker.dev_server.host_with_port).to eq "localhost:3035"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "doesn't use pretty in development environment" do
|
|
37
|
+
with_rails_env("development") do
|
|
38
|
+
expect(Webpacker.dev_server.pretty?).to be false
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "users WEBPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
|
|
43
|
+
expect(Webpacker::DevServer::DEFAULT_ENV_PREFIX).to eq "WEBPACKER_DEV_SERVER"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
describe "DigestStrategy" do
|
|
2
|
+
def remove_compilation_digest_path
|
|
3
|
+
@digest_strategy.send(:compilation_digest_path).tap do |path|
|
|
4
|
+
path.delete if path.exist?
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
before :all do
|
|
9
|
+
@digest_strategy = Webpacker::DigestStrategy.new
|
|
10
|
+
remove_compilation_digest_path
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
after :all do
|
|
14
|
+
remove_compilation_digest_path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "is not fresh before compilation" do
|
|
18
|
+
expect(@digest_strategy.stale?).to be true
|
|
19
|
+
expect(@digest_strategy.fresh?).to be_falsy
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "is fresh after compilation" do
|
|
23
|
+
@digest_strategy.after_compile_hook
|
|
24
|
+
expect(@digest_strategy.stale?).to be false
|
|
25
|
+
expect(@digest_strategy.fresh?).to be true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "generates correct compilation_digest_path" do
|
|
29
|
+
actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
|
|
30
|
+
expected_path = "last-compilation-digest-#{Webpacker.env}"
|
|
31
|
+
expect(actual_path).to eq expected_path
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class EngineRakeTasksTest < Minitest::Test
|
|
4
|
-
def setup
|
|
1
|
+
describe "EngineRakeTasks" do
|
|
2
|
+
before :context do
|
|
5
3
|
remove_webpack_binstubs
|
|
6
4
|
end
|
|
7
5
|
|
|
8
|
-
|
|
6
|
+
after :context do
|
|
9
7
|
remove_webpack_binstubs
|
|
10
8
|
end
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
it "mounts app:webpacker task successfully" do
|
|
13
11
|
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
|
14
|
-
|
|
12
|
+
expect(output).to include "app:webpacker"
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
|
|
15
|
+
it "binstubs adds only expected files to bin directory" do
|
|
16
|
+
original_files_in_bin = current_files_in_bin
|
|
17
|
+
|
|
18
18
|
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
|
|
19
|
-
webpack_binstub_paths.each { |path|
|
|
19
|
+
webpack_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
|
20
|
+
|
|
21
|
+
# and no other files are added
|
|
22
|
+
expect(current_files_in_bin - webpack_binstub_paths).to match_array original_files_in_bin
|
|
20
23
|
end
|
|
21
24
|
|
|
22
25
|
private
|
|
@@ -24,8 +27,13 @@ class EngineRakeTasksTest < Minitest::Test
|
|
|
24
27
|
File.expand_path("mounted_app", __dir__)
|
|
25
28
|
end
|
|
26
29
|
|
|
30
|
+
def current_files_in_bin
|
|
31
|
+
Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
|
|
32
|
+
end
|
|
33
|
+
|
|
27
34
|
def webpack_binstub_paths
|
|
28
35
|
[
|
|
36
|
+
"#{mounted_app_path}/test/dummy/bin/yarn",
|
|
29
37
|
"#{mounted_app_path}/test/dummy/bin/webpacker",
|
|
30
38
|
"#{mounted_app_path}/test/dummy/bin/webpacker-dev-server",
|
|
31
39
|
]
|
data/spec/env_spec.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
RSpec.describe "Env" do
|
|
2
|
+
it "uses the same env for Rails and Webpacker" do
|
|
3
|
+
expect(Webpacker.env).to eq Rails.env
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
it "uses production env without config" do
|
|
7
|
+
with_rails_env("foo") do
|
|
8
|
+
expect(Webpacker.env).to eq "production"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "uses the given env in custom config" do
|
|
13
|
+
with_rails_env("staging") do
|
|
14
|
+
expect(Webpacker.env).to eq "staging"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "uses 'production' as default env" do
|
|
19
|
+
expect(Webpacker::DEFAULT_ENV).to eq "production"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/spec/helper_spec.rb
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
module ActionView::TestCase::Behavior
|
|
2
|
+
attr_accessor :request
|
|
3
|
+
|
|
4
|
+
describe "Webpacker::Helper" do
|
|
5
|
+
let(:application_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css] }
|
|
6
|
+
let(:hello_stimulus_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css] }
|
|
7
|
+
|
|
8
|
+
before :each do
|
|
9
|
+
extend Webpacker::Helper
|
|
10
|
+
extend ActionView::Helpers
|
|
11
|
+
extend ActionView::Helpers::AssetTagHelper
|
|
12
|
+
extend ActionView::TestCase::Behavior
|
|
13
|
+
|
|
14
|
+
@request = Class.new do
|
|
15
|
+
def send_early_hints(links) end
|
|
16
|
+
def base_url
|
|
17
|
+
"https://example.com"
|
|
18
|
+
end
|
|
19
|
+
end.new
|
|
20
|
+
@javascript_pack_tag_loaded = nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "#asset_pack_path generates correct path" do
|
|
24
|
+
expect(asset_pack_path("bootstrap.js")).to eq "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
25
|
+
expect(asset_pack_path("bootstrap.css")).to eq "/packs/bootstrap-c38deda30895059837cf.css"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "#asset_pack_url generates correct url" do
|
|
29
|
+
expect(asset_pack_url("bootstrap.js")).to eq "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
|
30
|
+
expect(asset_pack_url("bootstrap.css")).to eq "https://example.com/packs/bootstrap-c38deda30895059837cf.css"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "#image_pack_path generates correct path" do
|
|
34
|
+
expect(image_pack_path("application.png")).to eq "/packs/application-k344a6d59eef8632c9d1.png"
|
|
35
|
+
expect(image_pack_path("image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
|
|
36
|
+
expect(image_pack_path("static/image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
|
|
37
|
+
expect(image_pack_path("nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
|
|
38
|
+
expect(image_pack_path("static/nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "#image_pack_url generates correct path" do
|
|
42
|
+
expect(image_pack_url("application.png")).to eq "https://example.com/packs/application-k344a6d59eef8632c9d1.png"
|
|
43
|
+
expect(image_pack_url("image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
|
|
44
|
+
expect(image_pack_url("static/image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
|
|
45
|
+
expect(image_pack_url("nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
|
|
46
|
+
expect(image_pack_url("static/nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "#image_pack_tag generates correct tags" do
|
|
50
|
+
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\" />"
|
|
51
|
+
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\" />"
|
|
52
|
+
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\" />"
|
|
53
|
+
expect(image_pack_tag("nested/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
|
|
54
|
+
expect(image_pack_tag("static/nested/image.jpg", size: "16x10", alt: "Edit Entry")).to eq "<img alt=\"Edit Entry\" src=\"/packs/static/nested/image-c38deda30895059837cf.jpg\" width=\"16\" height=\"10\" />"
|
|
55
|
+
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\" />"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "#favicon_pack_tag generates correct tags" do
|
|
59
|
+
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\" />"
|
|
60
|
+
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\" />"
|
|
61
|
+
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\" />"
|
|
62
|
+
expect(favicon_pack_tag("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\" />"
|
|
63
|
+
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\" />"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "#preload_pack_asset generates correct tag" do
|
|
67
|
+
if self.class.method_defined?(:preload_link_tag)
|
|
68
|
+
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">)
|
|
69
|
+
else
|
|
70
|
+
expect { preload_pack_asset("fonts/fa-regular-400.woff2") }.to raise_error "You need Rails >= 5.2 to use this tag."
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "#javascript_pack_tag generates correct tags" do
|
|
75
|
+
expected = <<~HTML.chomp
|
|
76
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
|
77
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
|
78
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
|
79
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
|
|
80
|
+
HTML
|
|
81
|
+
|
|
82
|
+
expect(javascript_pack_tag("application", "bootstrap")).to eq expected
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "#javascript_pack_tag generates correct tags by passing `defer: false`" do
|
|
86
|
+
expected = <<~HTML.chomp
|
|
87
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>
|
|
88
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>
|
|
89
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>
|
|
90
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
|
|
91
|
+
HTML
|
|
92
|
+
|
|
93
|
+
expect(javascript_pack_tag("application", "bootstrap", defer: false)).to eq expected
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it "#javascript_pack_tag generates correct appended tag" do
|
|
97
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
|
98
|
+
|
|
99
|
+
expected = <<~HTML.chomp
|
|
100
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
|
101
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
|
102
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
|
103
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
|
|
104
|
+
HTML
|
|
105
|
+
|
|
106
|
+
expect(javascript_pack_tag("application")).to eq expected
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "#javascript_pack_tag generates correct prepended tag" do
|
|
110
|
+
append_javascript_pack_tag("bootstrap")
|
|
111
|
+
prepend_javascript_pack_tag("main")
|
|
112
|
+
|
|
113
|
+
expected = <<~HTML.chomp
|
|
114
|
+
<script src="/packs/main-e323a53c7f30f5d53cbb.js" defer="defer"></script>
|
|
115
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
|
|
116
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
|
117
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
|
118
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
|
119
|
+
HTML
|
|
120
|
+
|
|
121
|
+
expect(javascript_pack_tag("application")).to eq expected
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
it "#append_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
|
|
125
|
+
expected_error_message = \
|
|
126
|
+
"You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
|
|
127
|
+
"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"
|
|
128
|
+
|
|
129
|
+
expect {
|
|
130
|
+
javascript_pack_tag("application")
|
|
131
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
|
132
|
+
}.to raise_error(expected_error_message)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "#prepend_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
|
|
136
|
+
expected_error_message = \
|
|
137
|
+
"You can only call prepend_javascript_pack_tag before javascript_pack_tag helper. " +
|
|
138
|
+
"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"
|
|
139
|
+
|
|
140
|
+
expect {
|
|
141
|
+
javascript_pack_tag("application")
|
|
142
|
+
prepend_javascript_pack_tag("bootstrap", defer: false)
|
|
143
|
+
}.to raise_error(expected_error_message)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
it "#javascript_pack_tag generates correct tags by passing `defer: true`" do
|
|
147
|
+
expected = <<~HTML.chomp
|
|
148
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
|
149
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
|
150
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
|
151
|
+
HTML
|
|
152
|
+
|
|
153
|
+
expect(javascript_pack_tag("application", defer: true)).to eq expected
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "#javascript_pack_tag generates correct tags by passing symbol" do
|
|
157
|
+
expected = <<~HTML.chomp
|
|
158
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
|
159
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
|
160
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
|
161
|
+
HTML
|
|
162
|
+
|
|
163
|
+
expect(javascript_pack_tag(:application)).to eq expected
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "#javascript_pack_tag rases error on multiple invocations" do
|
|
167
|
+
expected_error_message = "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " +
|
|
168
|
+
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
|
|
169
|
+
|
|
170
|
+
expect {
|
|
171
|
+
javascript_pack_tag(:application)
|
|
172
|
+
javascript_pack_tag(:bootstrap)
|
|
173
|
+
}.to raise_error(expected_error_message)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
it "#stylesheet_pack_tag generates correct link tag with string arguments" do
|
|
177
|
+
expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
178
|
+
.uniq
|
|
179
|
+
.map { |chunk| stylesheet_link_tag(chunk) }
|
|
180
|
+
.join("\n")
|
|
181
|
+
|
|
182
|
+
expect(stylesheet_pack_tag("application", "hello_stimulus")).to eq expected
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it "#stylesheet_pack_tag generates correct link tag with symbol arguments" do
|
|
186
|
+
expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
|
187
|
+
.uniq
|
|
188
|
+
.map { |chunk| stylesheet_link_tag(chunk) }
|
|
189
|
+
.join("\n")
|
|
190
|
+
|
|
191
|
+
expect(stylesheet_pack_tag(:application, :hello_stimulus)).to eq expected
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
it "#stylesheet_pack_tag generates correct link tag with mixed arguments" do
|
|
195
|
+
expected = (application_stylesheet_chunks)
|
|
196
|
+
.map { |chunk| stylesheet_link_tag(chunk, media: "all") }
|
|
197
|
+
.join("\n")
|
|
198
|
+
|
|
199
|
+
expect(stylesheet_pack_tag("application", media: "all")).to eq expected
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it "#stylesheet_pack_tag allows multiple invocations" do
|
|
203
|
+
app_style = stylesheet_pack_tag(:application)
|
|
204
|
+
stimulus_style = stylesheet_pack_tag(:hello_stimulus)
|
|
205
|
+
|
|
206
|
+
expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
|
207
|
+
|
|
208
|
+
expect(stimulus_style).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
|
209
|
+
|
|
210
|
+
expect {
|
|
211
|
+
stylesheet_pack_tag(:application)
|
|
212
|
+
stylesheet_pack_tag(:hello_stimulus)
|
|
213
|
+
}.to_not raise_error
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it "#stylesheet_pack_tag appends" do
|
|
217
|
+
append_stylesheet_pack_tag(:hello_stimulus)
|
|
218
|
+
|
|
219
|
+
expect(stylesheet_pack_tag(:application)).to eq \
|
|
220
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "#stylesheet_pack_tag appends duplicate" do
|
|
224
|
+
append_stylesheet_pack_tag(:hello_stimulus)
|
|
225
|
+
append_stylesheet_pack_tag(:application)
|
|
226
|
+
|
|
227
|
+
expect(stylesheet_pack_tag(:application)).to eq \
|
|
228
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
it "#stylesheet_pack_tag supports multiple invocations with different media attr" do
|
|
232
|
+
app_style = stylesheet_pack_tag(:application)
|
|
233
|
+
app_style_with_media = stylesheet_pack_tag(:application, media: "print")
|
|
234
|
+
hello_stimulus_style_with_media = stylesheet_pack_tag(:hello_stimulus, media: "all")
|
|
235
|
+
|
|
236
|
+
expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
|
237
|
+
expect(app_style_with_media).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "print") }.join("\n")
|
|
238
|
+
expect(hello_stimulus_style_with_media).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n")
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|