shakapacker 6.6.0 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-backward-compatibility.yml +43 -0
- data/CHANGELOG.md +50 -4
- data/CONTRIBUTING.md +4 -4
- data/Gemfile.development_dependencies +1 -1
- data/README.md +113 -88
- data/Rakefile +5 -0
- data/config/shakapacker.yml +1 -0
- data/docs/deployment.md +12 -10
- data/docs/developing_webpacker.md +5 -5
- data/docs/react.md +10 -6
- data/docs/style_loader_vs_mini_css.md +2 -2
- data/docs/troubleshooting.md +22 -18
- data/docs/using_esbuild_loader.md +5 -3
- data/docs/using_swc_loader.md +2 -2
- data/docs/v6_upgrade.md +2 -2
- data/docs/v7_upgrade.md +56 -0
- data/lib/install/bin/shakapacker +13 -0
- data/lib/install/bin/shakapacker-dev-server +13 -0
- data/lib/install/config/{webpacker.yml → shakapacker.yml} +13 -8
- data/lib/install/template.rb +7 -7
- data/lib/{webpacker → shakapacker}/base_strategy.rb +2 -2
- data/lib/{webpacker → shakapacker}/commands.rb +4 -4
- data/lib/{webpacker → shakapacker}/compiler.rb +43 -15
- data/lib/{webpacker → shakapacker}/compiler_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/configuration.rb +52 -21
- data/lib/shakapacker/deprecation_helper.rb +88 -0
- data/lib/{webpacker → shakapacker}/dev_server.rb +27 -4
- data/lib/{webpacker → shakapacker}/dev_server_proxy.rb +4 -4
- data/lib/shakapacker/dev_server_runner.rb +104 -0
- data/lib/{webpacker → shakapacker}/digest_strategy.rb +6 -6
- data/lib/{webpacker → shakapacker}/env.rb +8 -8
- data/lib/{webpacker → shakapacker}/helper.rb +20 -20
- data/lib/{webpacker → shakapacker}/instance.rb +13 -10
- data/lib/{webpacker → shakapacker}/manifest.rb +14 -14
- data/lib/{webpacker → shakapacker}/mtime_strategy.rb +5 -5
- data/lib/shakapacker/railtie.rb +70 -0
- data/lib/shakapacker/runner.rb +28 -0
- data/lib/shakapacker/utils/version_syntax_converter.rb +2 -2
- data/lib/{webpacker → shakapacker}/version.rb +2 -2
- data/lib/{webpacker → shakapacker}/version_checker.rb +8 -8
- data/lib/shakapacker/webpack_runner.rb +67 -0
- data/lib/shakapacker.rb +51 -1
- data/lib/tasks/shakapacker/binstubs.rake +15 -0
- data/lib/tasks/shakapacker/check_binstubs.rake +25 -0
- data/lib/tasks/shakapacker/check_node.rake +31 -0
- data/lib/tasks/shakapacker/check_yarn.rake +33 -0
- data/lib/tasks/shakapacker/clean.rake +23 -0
- data/lib/tasks/shakapacker/clobber.rake +18 -0
- data/lib/tasks/shakapacker/compile.rake +31 -0
- data/lib/tasks/shakapacker/info.rake +21 -0
- data/lib/tasks/shakapacker/install.rake +17 -0
- data/lib/tasks/shakapacker/verify_config.rake +12 -0
- data/lib/tasks/shakapacker/verify_install.rake +4 -0
- data/lib/tasks/shakapacker/yarn_install.rake +24 -0
- data/lib/tasks/shakapacker.rake +18 -0
- data/lib/tasks/webpacker/binstubs.rake +5 -11
- data/lib/tasks/webpacker/check_binstubs.rake +6 -9
- data/lib/tasks/webpacker/check_node.rake +5 -27
- data/lib/tasks/webpacker/check_yarn.rake +5 -29
- data/lib/tasks/webpacker/clean.rake +5 -19
- data/lib/tasks/webpacker/clobber.rake +6 -13
- data/lib/tasks/webpacker/compile.rake +5 -33
- data/lib/tasks/webpacker/info.rake +5 -17
- data/lib/tasks/webpacker/install.rake +5 -13
- data/lib/tasks/webpacker/verify_config.rake +6 -11
- data/lib/tasks/webpacker/verify_install.rake +7 -2
- data/lib/tasks/webpacker/yarn_install.rake +5 -20
- data/lib/tasks/webpacker.rake +15 -13
- data/lib/webpacker/dev_server_runner.rb +9 -96
- data/lib/webpacker/webpack_runner.rb +9 -58
- data/lib/webpacker.rb +3 -47
- data/package/__tests__/config-bc.js +27 -0
- data/package/__tests__/config.js +6 -5
- data/package/__tests__/dev_server-bc.js +46 -0
- data/package/__tests__/dev_server.js +9 -8
- data/package/__tests__/development-bc.js +66 -0
- data/package/__tests__/development.js +36 -5
- data/package/__tests__/env-bc.js +59 -0
- data/package/__tests__/env.js +3 -2
- data/package/__tests__/index.js +13 -0
- data/package/__tests__/production-bc.js +51 -0
- data/package/__tests__/production.js +25 -3
- data/package/__tests__/staging-bc.js +53 -0
- data/package/__tests__/staging.js +27 -4
- data/package/__tests__/test-bc.js +43 -0
- data/package/__tests__/test.js +22 -4
- data/package/babel/preset.js +1 -4
- data/package/config.js +25 -7
- data/package/dev_server.js +7 -4
- data/package/env.js +22 -3
- data/package/environments/__tests__/base-bc.js +107 -0
- data/package/environments/__tests__/base.js +13 -13
- data/package/environments/base.js +1 -1
- data/package/environments/development.js +4 -46
- data/package/environments/production.js +1 -1
- data/package/index.js +11 -4
- data/package/rules/__tests__/__utils__/webpack.js +1 -1
- data/package/rules/__tests__/file.js +27 -0
- data/package/rules/__tests__/swc.js +1 -2
- data/package/rules/file.js +2 -2
- data/package/utils/configPath.js +19 -0
- data/package/utils/defaultConfigPath.js +2 -0
- data/package/utils/get_style_rule.js +5 -2
- data/package/utils/helpers.js +24 -1
- data/package/utils/inliningCss.js +7 -0
- data/package/utils/snakeToCamelCase +7 -0
- data/package/webpackDevServerConfig.js +68 -0
- data/package.json +2 -2
- data/{webpacker.gemspec → shakapacker.gemspec} +3 -3
- data/spec/backward_compatibility_specs/command_spec_bc.rb +116 -0
- data/spec/backward_compatibility_specs/compiler_spec_bc.rb +59 -0
- data/spec/backward_compatibility_specs/compiler_strategy_spec_bc.rb +22 -0
- data/spec/backward_compatibility_specs/configuration_spec_bc.rb +286 -0
- data/spec/backward_compatibility_specs/dev_server_runner_spec_bc.rb +79 -0
- data/spec/backward_compatibility_specs/dev_server_spec_bc.rb +47 -0
- data/spec/backward_compatibility_specs/digest_strategy_spec_bc.rb +35 -0
- data/spec/backward_compatibility_specs/engine_rake_tasks_spec_bc.rb +44 -0
- data/spec/backward_compatibility_specs/env_spec_bc.rb +23 -0
- data/spec/backward_compatibility_specs/helper_spec_bc.rb +243 -0
- data/spec/backward_compatibility_specs/instance_spec_bc.rb +31 -0
- data/spec/backward_compatibility_specs/manifest_spec_bc.rb +100 -0
- data/spec/backward_compatibility_specs/mtime_strategy_spec_bc.rb +55 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec_bc.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/spec/backward_compatibility_specs/webpack_runner_spec_bc.rb +56 -0
- data/spec/backward_compatibility_specs/webpacker_spec_bc.rb +41 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/Rakefile +3 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/application.js +1 -1
- data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/application.rb +11 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/environment.rb +4 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpack/webpack.config.js +0 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_css_extract_ignore_order_warnings.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_defaults_fallback.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config/webpacker_no_precompile.yml +7 -0
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_other_location.yml +1 -1
- data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_public_root.yml +1 -1
- data/spec/backward_compatibility_specs/webpacker_test_app/config.ru +5 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/package.json +13 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/public/packs/manifest.json +58 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/some.config.js +0 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/yarn.lock +11 -0
- data/spec/command_spec.rb +18 -16
- data/spec/compiler_spec.rb +19 -17
- data/spec/compiler_strategy_spec.rb +9 -7
- data/spec/configuration_spec.rb +108 -66
- data/spec/dev_server_runner_spec.rb +9 -8
- data/spec/dev_server_spec.rb +97 -9
- data/spec/digest_strategy_spec.rb +4 -2
- data/spec/engine_rake_tasks_spec.rb +12 -16
- data/spec/env_spec.rb +7 -5
- data/spec/helper_spec.rb +4 -2
- data/spec/instance_spec.rb +31 -0
- data/spec/manifest_spec.rb +21 -19
- data/spec/mounted_app/test/dummy/config/application.rb +1 -1
- data/spec/mounted_app/test/dummy/config/webpacker.yml +3 -3
- data/spec/mtime_strategy_spec.rb +4 -2
- data/spec/rake_tasks_spec.rb +20 -18
- data/spec/spec_helper.rb +0 -25
- data/spec/spec_helper_initializer.rb +24 -0
- data/spec/test_app/.gitignore +2 -0
- data/spec/test_app/app/javascript/entrypoints/application.js +10 -0
- data/spec/test_app/app/javascript/entrypoints/generated/something.js +2 -0
- data/spec/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/spec/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/spec/test_app/bin/{webpacker-dev-server → shakapacker} +3 -3
- data/spec/test_app/bin/{webpacker → shakapacker-dev-server} +3 -3
- data/spec/test_app/config/application.rb +1 -1
- data/spec/test_app/config/shakapacker.yml +82 -0
- data/spec/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
- data/spec/test_app/config/shakapacker_defaults_fallback.yml +11 -0
- data/spec/test_app/config/shakapacker_manifest_path.yml +80 -0
- data/spec/test_app/config/shakapacker_nested_entries.yml +83 -0
- data/spec/test_app/config/shakapacker_no_precompile.yml +7 -0
- data/spec/test_app/config/shakapacker_other_location.yml +85 -0
- data/spec/test_app/config/shakapacker_public_root.yml +18 -0
- data/spec/version_checker_spec.rb +16 -15
- data/spec/webpack_runner_spec.rb +4 -3
- data/spec/webpacker_spec.rb +9 -29
- metadata +119 -44
- data/config/webpacker.yml +0 -1
- data/lib/webpacker/railtie.rb +0 -70
- data/lib/webpacker/runner.rb +0 -23
- data/package/configPath.js +0 -3
- data/package/inliningCss.js +0 -7
- data/spec/test_app/config/webpacker_no_precompile.yml +0 -7
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/generated/something.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.css +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/app/packs/entrypoints/multi_entry.js +0 -0
- /data/{lib/install → spec/backward_compatibility_specs/webpacker_test_app}/bin/webpacker-dev-server +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_manifest_path.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "DevServer" do
|
4
|
+
it "doesn't run by default" do
|
5
|
+
expect(Webpacker.dev_server.running?).to be_falsy
|
6
|
+
end
|
7
|
+
|
8
|
+
it "uses localhost as host in development environment" do
|
9
|
+
with_rails_env("development") do
|
10
|
+
expect(Webpacker.dev_server.host).to eq "localhost"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses port 3035 in development environment" do
|
15
|
+
with_rails_env("development") do
|
16
|
+
expect(Webpacker.dev_server.port).to eq 3035
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "doesn't use https in development environment" do
|
21
|
+
with_rails_env("development") do
|
22
|
+
expect(Webpacker.dev_server.https?).to be false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses http protocol in development environment" do
|
27
|
+
with_rails_env("development") do
|
28
|
+
expect(Webpacker.dev_server.protocol).to eq "http"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "sets host_with_port to localhost:3035 in development environment" do
|
33
|
+
with_rails_env("development") do
|
34
|
+
expect(Webpacker.dev_server.host_with_port).to eq "localhost:3035"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "doesn't use pretty in development environment" do
|
39
|
+
with_rails_env("development") do
|
40
|
+
expect(Webpacker.dev_server.pretty?).to be false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
|
45
|
+
expect(Webpacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "DigestStrategy" do
|
4
|
+
def remove_compilation_digest_path
|
5
|
+
@digest_strategy.send(:compilation_digest_path).tap do |path|
|
6
|
+
path.delete if path.exist?
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
@digest_strategy = Webpacker::DigestStrategy.new
|
12
|
+
remove_compilation_digest_path
|
13
|
+
end
|
14
|
+
|
15
|
+
after :all do
|
16
|
+
remove_compilation_digest_path
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is not fresh before compilation" do
|
20
|
+
expect(@digest_strategy.stale?).to be true
|
21
|
+
expect(@digest_strategy.fresh?).to be_falsy
|
22
|
+
end
|
23
|
+
|
24
|
+
it "is fresh after compilation" do
|
25
|
+
@digest_strategy.after_compile_hook
|
26
|
+
expect(@digest_strategy.stale?).to be false
|
27
|
+
expect(@digest_strategy.fresh?).to be true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "generates correct compilation_digest_path" do
|
31
|
+
actual_path = @digest_strategy.send(:compilation_digest_path).basename.to_s
|
32
|
+
expected_path = "last-compilation-digest-#{Webpacker.env}"
|
33
|
+
expect(actual_path).to eq expected_path
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "EngineRakeTasks" do
|
4
|
+
before :context do
|
5
|
+
remove_webpack_binstubs
|
6
|
+
end
|
7
|
+
|
8
|
+
after :context do
|
9
|
+
remove_webpack_binstubs
|
10
|
+
end
|
11
|
+
|
12
|
+
it "mounts app:webpacker task successfully" do
|
13
|
+
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
14
|
+
expect(output).to match /app:webpacker.+DEPRECATED/
|
15
|
+
expect(output).to match /app:webpacker:binstubs.+DEPRECATED/
|
16
|
+
end
|
17
|
+
|
18
|
+
it "binstubs adds only expected files to bin directory" do
|
19
|
+
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
|
20
|
+
expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def mounted_app_path
|
25
|
+
File.expand_path("../mounted_app", __dir__)
|
26
|
+
end
|
27
|
+
|
28
|
+
def current_files_in_bin
|
29
|
+
Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
|
30
|
+
end
|
31
|
+
|
32
|
+
def expected_binstub_paths
|
33
|
+
gem_path = File.expand_path("../..", __dir__)
|
34
|
+
Dir.chdir("#{gem_path}/lib/install/bin") do
|
35
|
+
Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def remove_webpack_binstubs
|
40
|
+
expected_binstub_paths.each do |path|
|
41
|
+
File.delete(path) if File.exist?(path)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
RSpec.describe "Webpacker.env" do
|
4
|
+
it "uses the same env for Rails and Webpacker" do
|
5
|
+
expect(Webpacker.env).to eq Rails.env
|
6
|
+
end
|
7
|
+
|
8
|
+
it "uses production env without config" do
|
9
|
+
with_rails_env("foo") do
|
10
|
+
expect(Webpacker.env).to eq "production"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "uses the given env in custom config" do
|
15
|
+
with_rails_env("staging") do
|
16
|
+
expect(Webpacker.env).to eq "staging"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "uses 'production' as default env" do
|
21
|
+
expect(Webpacker::DEFAULT_ENV).to eq "production"
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
module ActionView::TestCase::Behavior
|
4
|
+
attr_accessor :request
|
5
|
+
|
6
|
+
describe "Webpacker::Helper" do
|
7
|
+
let(:application_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/application-k344a6d59eef8632c9d1.chunk.css] }
|
8
|
+
let(:hello_stimulus_stylesheet_chunks) { %w[/packs/1-c20632e7baf2c81200d3.chunk.css /packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css] }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
extend Webpacker::Helper
|
12
|
+
extend ActionView::Helpers
|
13
|
+
extend ActionView::Helpers::AssetTagHelper
|
14
|
+
extend ActionView::TestCase::Behavior
|
15
|
+
|
16
|
+
@request = Class.new do
|
17
|
+
def send_early_hints(links) end
|
18
|
+
def base_url
|
19
|
+
"https://example.com"
|
20
|
+
end
|
21
|
+
end.new
|
22
|
+
@javascript_pack_tag_loaded = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#asset_pack_path generates correct path" do
|
26
|
+
expect(asset_pack_path("bootstrap.js")).to eq "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
27
|
+
expect(asset_pack_path("bootstrap.css")).to eq "/packs/bootstrap-c38deda30895059837cf.css"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#asset_pack_url generates correct url" do
|
31
|
+
expect(asset_pack_url("bootstrap.js")).to eq "https://example.com/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
32
|
+
expect(asset_pack_url("bootstrap.css")).to eq "https://example.com/packs/bootstrap-c38deda30895059837cf.css"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#image_pack_path generates correct path" do
|
36
|
+
expect(image_pack_path("application.png")).to eq "/packs/application-k344a6d59eef8632c9d1.png"
|
37
|
+
expect(image_pack_path("image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
|
38
|
+
expect(image_pack_path("static/image.jpg")).to eq "/packs/static/image-c38deda30895059837cf.jpg"
|
39
|
+
expect(image_pack_path("nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
|
40
|
+
expect(image_pack_path("static/nested/image.jpg")).to eq "/packs/static/nested/image-c38deda30895059837cf.jpg"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "#image_pack_url generates correct path" do
|
44
|
+
expect(image_pack_url("application.png")).to eq "https://example.com/packs/application-k344a6d59eef8632c9d1.png"
|
45
|
+
expect(image_pack_url("image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
|
46
|
+
expect(image_pack_url("static/image.jpg")).to eq "https://example.com/packs/static/image-c38deda30895059837cf.jpg"
|
47
|
+
expect(image_pack_url("nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
|
48
|
+
expect(image_pack_url("static/nested/image.jpg")).to eq "https://example.com/packs/static/nested/image-c38deda30895059837cf.jpg"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "#image_pack_tag generates correct tags" do
|
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
|
+
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
|
+
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\" />"
|
55
|
+
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\" />"
|
56
|
+
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\" />"
|
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
|
+
end
|
59
|
+
|
60
|
+
it "#favicon_pack_tag generates correct tags" do
|
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
|
+
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
|
+
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\" />"
|
64
|
+
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\" />"
|
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
|
+
end
|
67
|
+
|
68
|
+
it "#preload_pack_asset generates correct tag" do
|
69
|
+
if self.class.method_defined?(:preload_link_tag)
|
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
|
+
else
|
72
|
+
expect { preload_pack_asset("fonts/fa-regular-400.woff2") }.to raise_error "You need Rails >= 5.2 to use this tag."
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "#javascript_pack_tag generates correct tags" do
|
77
|
+
expected = <<~HTML.chomp
|
78
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
79
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
80
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
81
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
|
82
|
+
HTML
|
83
|
+
|
84
|
+
expect(javascript_pack_tag("application", "bootstrap")).to eq expected
|
85
|
+
end
|
86
|
+
|
87
|
+
it "#javascript_pack_tag generates correct tags by passing `defer: false`" do
|
88
|
+
expected = <<~HTML.chomp
|
89
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js"></script>
|
90
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js"></script>
|
91
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js"></script>
|
92
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
|
93
|
+
HTML
|
94
|
+
|
95
|
+
expect(javascript_pack_tag("application", "bootstrap", defer: false)).to eq expected
|
96
|
+
end
|
97
|
+
|
98
|
+
it "#javascript_pack_tag generates correct appended tag" do
|
99
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
100
|
+
|
101
|
+
expected = <<~HTML.chomp
|
102
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
103
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
104
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
105
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js"></script>
|
106
|
+
HTML
|
107
|
+
|
108
|
+
expect(javascript_pack_tag("application")).to eq expected
|
109
|
+
end
|
110
|
+
|
111
|
+
it "#javascript_pack_tag generates correct prepended tag" do
|
112
|
+
append_javascript_pack_tag("bootstrap")
|
113
|
+
prepend_javascript_pack_tag("main")
|
114
|
+
|
115
|
+
expected = <<~HTML.chomp
|
116
|
+
<script src="/packs/main-e323a53c7f30f5d53cbb.js" defer="defer"></script>
|
117
|
+
<script src="/packs/bootstrap-300631c4f0e0f9c865bc.js" defer="defer"></script>
|
118
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
119
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
120
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
121
|
+
HTML
|
122
|
+
|
123
|
+
expect(javascript_pack_tag("application")).to eq expected
|
124
|
+
end
|
125
|
+
|
126
|
+
it "#append_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
|
127
|
+
expected_error_message = \
|
128
|
+
"You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
|
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"
|
130
|
+
|
131
|
+
expect {
|
132
|
+
javascript_pack_tag("application")
|
133
|
+
append_javascript_pack_tag("bootstrap", defer: false)
|
134
|
+
}.to raise_error(expected_error_message)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "#prepend_javascript_pack_tag raises error if called after calling #javascript_pack_tag" do
|
138
|
+
expected_error_message = \
|
139
|
+
"You can only call prepend_javascript_pack_tag before javascript_pack_tag helper. " +
|
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"
|
141
|
+
|
142
|
+
expect {
|
143
|
+
javascript_pack_tag("application")
|
144
|
+
prepend_javascript_pack_tag("bootstrap", defer: false)
|
145
|
+
}.to raise_error(expected_error_message)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "#javascript_pack_tag generates correct tags by passing `defer: true`" do
|
149
|
+
expected = <<~HTML.chomp
|
150
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
151
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
152
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
153
|
+
HTML
|
154
|
+
|
155
|
+
expect(javascript_pack_tag("application", defer: true)).to eq expected
|
156
|
+
end
|
157
|
+
|
158
|
+
it "#javascript_pack_tag generates correct tags by passing symbol" do
|
159
|
+
expected = <<~HTML.chomp
|
160
|
+
<script src="/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js" defer="defer"></script>
|
161
|
+
<script src="/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js" defer="defer"></script>
|
162
|
+
<script src="/packs/application-k344a6d59eef8632c9d1.js" defer="defer"></script>
|
163
|
+
HTML
|
164
|
+
|
165
|
+
expect(javascript_pack_tag(:application)).to eq expected
|
166
|
+
end
|
167
|
+
|
168
|
+
it "#javascript_pack_tag rases error on multiple invocations" do
|
169
|
+
expected_error_message = "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " +
|
170
|
+
"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"
|
171
|
+
|
172
|
+
expect {
|
173
|
+
javascript_pack_tag(:application)
|
174
|
+
javascript_pack_tag(:bootstrap)
|
175
|
+
}.to raise_error(expected_error_message)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "#stylesheet_pack_tag generates correct link tag with string arguments" do
|
179
|
+
expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
180
|
+
.uniq
|
181
|
+
.map { |chunk| stylesheet_link_tag(chunk) }
|
182
|
+
.join("\n")
|
183
|
+
|
184
|
+
expect(stylesheet_pack_tag("application", "hello_stimulus")).to eq expected
|
185
|
+
end
|
186
|
+
|
187
|
+
it "#stylesheet_pack_tag generates correct link tag with symbol arguments" do
|
188
|
+
expected = (application_stylesheet_chunks + hello_stimulus_stylesheet_chunks)
|
189
|
+
.uniq
|
190
|
+
.map { |chunk| stylesheet_link_tag(chunk) }
|
191
|
+
.join("\n")
|
192
|
+
|
193
|
+
expect(stylesheet_pack_tag(:application, :hello_stimulus)).to eq expected
|
194
|
+
end
|
195
|
+
|
196
|
+
it "#stylesheet_pack_tag generates correct link tag with mixed arguments" do
|
197
|
+
expected = (application_stylesheet_chunks)
|
198
|
+
.map { |chunk| stylesheet_link_tag(chunk, media: "all") }
|
199
|
+
.join("\n")
|
200
|
+
|
201
|
+
expect(stylesheet_pack_tag("application", media: "all")).to eq expected
|
202
|
+
end
|
203
|
+
|
204
|
+
it "#stylesheet_pack_tag allows multiple invocations" do
|
205
|
+
app_style = stylesheet_pack_tag(:application)
|
206
|
+
stimulus_style = stylesheet_pack_tag(:hello_stimulus)
|
207
|
+
|
208
|
+
expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
209
|
+
|
210
|
+
expect(stimulus_style).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
211
|
+
|
212
|
+
expect {
|
213
|
+
stylesheet_pack_tag(:application)
|
214
|
+
stylesheet_pack_tag(:hello_stimulus)
|
215
|
+
}.to_not raise_error
|
216
|
+
end
|
217
|
+
|
218
|
+
it "#stylesheet_pack_tag appends" do
|
219
|
+
append_stylesheet_pack_tag(:hello_stimulus)
|
220
|
+
|
221
|
+
expect(stylesheet_pack_tag(:application)).to eq \
|
222
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
223
|
+
end
|
224
|
+
|
225
|
+
it "#stylesheet_pack_tag appends duplicate" do
|
226
|
+
append_stylesheet_pack_tag(:hello_stimulus)
|
227
|
+
append_stylesheet_pack_tag(:application)
|
228
|
+
|
229
|
+
expect(stylesheet_pack_tag(:application)).to eq \
|
230
|
+
(application_stylesheet_chunks + hello_stimulus_stylesheet_chunks).uniq.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
231
|
+
end
|
232
|
+
|
233
|
+
it "#stylesheet_pack_tag supports multiple invocations with different media attr" do
|
234
|
+
app_style = stylesheet_pack_tag(:application)
|
235
|
+
app_style_with_media = stylesheet_pack_tag(:application, media: "print")
|
236
|
+
hello_stimulus_style_with_media = stylesheet_pack_tag(:hello_stimulus, media: "all")
|
237
|
+
|
238
|
+
expect(app_style).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk) }.join("\n")
|
239
|
+
expect(app_style_with_media).to eq application_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "print") }.join("\n")
|
240
|
+
expect(hello_stimulus_style_with_media).to eq hello_stimulus_stylesheet_chunks.map { |chunk| stylesheet_link_tag(chunk, media: "all") }.join("\n")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Webpacker::Instance" do
|
4
|
+
before :each do
|
5
|
+
ENV.delete("WEBPACKER_CONFIG")
|
6
|
+
ENV.delete("SHAKAPACKER_CONFIG")
|
7
|
+
Webpacker.instance = Webpacker::Instance.new
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
ENV.delete("WEBPACKER_CONFIG")
|
12
|
+
ENV.delete("SHAKAPACKER_CONFIG")
|
13
|
+
Webpacker.instance = Webpacker::Instance.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it "uses default config path if no env variable defined" do
|
17
|
+
actual_config_path = Rails.root.join("config/webpacker.yml")
|
18
|
+
expected_config_path = Webpacker.config.config_path
|
19
|
+
|
20
|
+
expect(expected_config_path).to eq(actual_config_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "uses WEBPACKER_CONFIG env variable for config file" do
|
24
|
+
ENV["WEBPACKER_CONFIG"] = "/some/random/path.yml"
|
25
|
+
|
26
|
+
actual_config_path = "/some/random/path.yml"
|
27
|
+
expected_config_path = Webpacker.config.config_path.to_s
|
28
|
+
|
29
|
+
expect(Webpacker.config.config_path.to_s).to eq("/some/random/path.yml")
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Webpacker::Manifest" do
|
4
|
+
let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "webpacker_test_app/public/packs", "manifest.json").to_s }
|
5
|
+
|
6
|
+
it "#lookup! throws exception for a non-existing asset file" do
|
7
|
+
asset_file = "calendar.js"
|
8
|
+
expected_error_message = "Shakapacker can't find #{asset_file} in #{manifest_path}"
|
9
|
+
|
10
|
+
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
11
|
+
|
12
|
+
expect {
|
13
|
+
Webpacker.manifest.lookup!(asset_file)
|
14
|
+
}.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#lookup! throws exception for a non-existing asset file with type and without extension" do
|
18
|
+
asset_file = "calendar"
|
19
|
+
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
20
|
+
|
21
|
+
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
22
|
+
|
23
|
+
expect {
|
24
|
+
Webpacker.manifest.lookup!(asset_file, type: :javascript)
|
25
|
+
}.to raise_error(Webpacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#lookup! returns path to bundled bootstrap.js" do
|
29
|
+
actual = Webpacker.manifest.lookup!("bootstrap.js")
|
30
|
+
expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
31
|
+
|
32
|
+
expect(actual).to eq expected
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#lookup_pack_with_chunks! returns array of path to bundled bootstrap with type of javascript" do
|
36
|
+
actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap", type: :javascript)
|
37
|
+
expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
|
38
|
+
|
39
|
+
expect(actual).to eq expected
|
40
|
+
end
|
41
|
+
|
42
|
+
it "#lookup_with_chunks! returns array of path to bundled bootstrap.js with type of javascript" do
|
43
|
+
actual = Webpacker.manifest.lookup_pack_with_chunks!("bootstrap.js", type: :javascript)
|
44
|
+
expected = ["/packs/bootstrap-300631c4f0e0f9c865bc.js"]
|
45
|
+
|
46
|
+
expect(actual).to eq expected
|
47
|
+
end
|
48
|
+
|
49
|
+
it "#lookup_with_chunks! returns array of path to bundled 'print/application' without extension and in a sub-directory" do
|
50
|
+
actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application", type: :css)
|
51
|
+
expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
|
52
|
+
|
53
|
+
expect(actual).to eq expected
|
54
|
+
end
|
55
|
+
|
56
|
+
it "#lookup_with_chunks! returns array of path to bundled 'print/application.css' in a sub-directory" do
|
57
|
+
actual = Webpacker.manifest.lookup_pack_with_chunks!("print/application.css", type: :css)
|
58
|
+
expected = ["/packs/print/application-983b6c164a47f7ed49cd.css"]
|
59
|
+
|
60
|
+
expect(actual).to eq expected
|
61
|
+
end
|
62
|
+
|
63
|
+
it "#lookup returns nil for non-existing asset file" do
|
64
|
+
expect(Webpacker.manifest.lookup("foo.js")).to be nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it "#lookup_pack_with_chunks returns nil for non-existing asset file" do
|
68
|
+
expect(Webpacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "#lookup returns path for bootstrap.js" do
|
72
|
+
actual = Webpacker.manifest.lookup("bootstrap.js")
|
73
|
+
expected = "/packs/bootstrap-300631c4f0e0f9c865bc.js"
|
74
|
+
|
75
|
+
expect(actual).to eq expected
|
76
|
+
end
|
77
|
+
|
78
|
+
it "#lookup_pack_with_chunks! throws exception for a non-existing asset file" do
|
79
|
+
asset_file = "calendar"
|
80
|
+
|
81
|
+
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
82
|
+
|
83
|
+
allow(Webpacker.config).to receive(:compile?).and_return(false)
|
84
|
+
|
85
|
+
expect {
|
86
|
+
Webpacker.manifest.lookup_pack_with_chunks!(asset_file, type: :javascript)
|
87
|
+
}.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "#lookup_pack_with_chunks! returns array of paths to bundled js files with 'application' in their name" do
|
91
|
+
actual_application_entrypoints = Webpacker.manifest.lookup_pack_with_chunks!("application", type: :javascript)
|
92
|
+
expected_application_entrypoints = [
|
93
|
+
"/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
|
94
|
+
"/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
|
95
|
+
"/packs/application-k344a6d59eef8632c9d1.js"
|
96
|
+
]
|
97
|
+
|
98
|
+
expect(actual_application_entrypoints).to eq expected_application_entrypoints
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Webpacker::MtimeStrategy" do
|
4
|
+
let(:mtime_strategy) { Webpacker::MtimeStrategy.new }
|
5
|
+
let(:manifest_timestamp) { Time.parse("2021-01-01 12:34:56 UTC") }
|
6
|
+
|
7
|
+
describe "#fresh?" do
|
8
|
+
it "returns false when manifest is missing" do
|
9
|
+
latest_timestamp = manifest_timestamp + 3600
|
10
|
+
|
11
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i, manifest_exists: false) do
|
12
|
+
expect(mtime_strategy.fresh?).to be false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false when manifest is older" do
|
17
|
+
latest_timestamp = manifest_timestamp + 3600
|
18
|
+
|
19
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
20
|
+
expect(mtime_strategy.fresh?).to be false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns true when manifest is new" do
|
25
|
+
latest_timestamp = manifest_timestamp - 3600
|
26
|
+
|
27
|
+
with_stubs(latest_timestamp: latest_timestamp.to_i) do
|
28
|
+
expect(mtime_strategy.fresh?).to be true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#stale?" do
|
34
|
+
it "returns false when #fresh? is true" do
|
35
|
+
expect(mtime_strategy).to receive(:fresh?).and_return(true)
|
36
|
+
|
37
|
+
expect(mtime_strategy.stale?).to be false
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns true when #fresh? is false" do
|
41
|
+
expect(mtime_strategy).to receive(:fresh?).and_return(false)
|
42
|
+
|
43
|
+
expect(mtime_strategy.stale?).to be true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def with_stubs(latest_timestamp:, manifest_exists: true)
|
50
|
+
allow(mtime_strategy).to receive(:latest_modified_timestamp).and_return(latest_timestamp)
|
51
|
+
allow(FileTest).to receive(:exist?).and_return(manifest_exists)
|
52
|
+
allow(File).to receive(:mtime).and_return(manifest_timestamp)
|
53
|
+
yield
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "RakeTasks" do
|
4
|
+
let(:test_app_path) { File.expand_path("webpacker_test_app", __dir__) }
|
5
|
+
|
6
|
+
it "`rake -T` lists Webpacker tasks" do
|
7
|
+
output = Dir.chdir(test_app_path) { `rake -T` }
|
8
|
+
expect(output).to match /webpacker .+DEPRECATED/
|
9
|
+
expect(output).to match /webpacker:check_binstubs.+DEPRECATED/
|
10
|
+
expect(output).to match /webpacker:check_node.+DEPRECATED/
|
11
|
+
expect(output).to match /webpacker:check_yarn.+DEPRECATED/
|
12
|
+
expect(output).to match /webpacker:clean.+DEPRECATED/
|
13
|
+
expect(output).to match /webpacker:clobber.+DEPRECATED/
|
14
|
+
expect(output).to match /webpacker:compile.+DEPRECATED/
|
15
|
+
expect(output).to match /webpacker:install.+DEPRECATED/
|
16
|
+
expect(output).to match /webpacker:verify_install.+DEPRECATED/
|
17
|
+
end
|
18
|
+
|
19
|
+
it "`webpacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
|
20
|
+
output = Dir.chdir(test_app_path) { `rake webpacker:check_binstubs 2>&1` }
|
21
|
+
expect(output).to_not include "webpack binstub not found."
|
22
|
+
expect(output).to include "DEPRECATION"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "`webpacker:check_node` doesn't get 'webpacker requires Node.js' error" do
|
26
|
+
output = Dir.chdir(test_app_path) { `rake webpacker:check_node 2>&1` }
|
27
|
+
expect(output).to_not include "Shakapacker requires Node.js"
|
28
|
+
expect(output).to include "DEPRECATION"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "`webpacker:check_yarn` doesn't get error related to yarn" do
|
32
|
+
output = Dir.chdir(test_app_path) { `rake webpacker:check_yarn 2>&1` }
|
33
|
+
expect(output).to_not include "Yarn not installed"
|
34
|
+
expect(output).to_not include "Shakapacker requires Yarn"
|
35
|
+
expect(output).to include "DEPRECATION"
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "webpacker_test_app/config/environment"
|
2
|
+
|
3
|
+
Rails.env = "production"
|
4
|
+
|
5
|
+
Webpacker.instance = ::Webpacker::Instance.new
|
6
|
+
|
7
|
+
def reloaded_config
|
8
|
+
Webpacker.instance.instance_variable_set(:@env, nil)
|
9
|
+
Webpacker.instance.instance_variable_set(:@config, nil)
|
10
|
+
Webpacker.instance.instance_variable_set(:@dev_server, nil)
|
11
|
+
Webpacker.env
|
12
|
+
Webpacker.config
|
13
|
+
Webpacker.dev_server
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_rails_env(env)
|
17
|
+
original = Rails.env
|
18
|
+
Rails.env = ActiveSupport::StringInquirer.new(env)
|
19
|
+
reloaded_config
|
20
|
+
yield
|
21
|
+
ensure
|
22
|
+
Rails.env = ActiveSupport::StringInquirer.new(original)
|
23
|
+
reloaded_config
|
24
|
+
end
|