shakapacker 8.0.0 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/dummy.yml +1 -1
- data/.github/workflows/generator.yml +5 -1
- data/.github/workflows/node.yml +1 -1
- data/.github/workflows/ruby.yml +8 -2
- data/.gitignore +0 -1
- data/.node-version +1 -1
- data/CHANGELOG.md +21 -12
- data/Gemfile.lock +257 -0
- data/README.md +11 -12
- data/docs/customizing_babel_config.md +32 -4
- data/docs/react.md +3 -2
- data/docs/troubleshooting.md +1 -1
- data/docs/v8_upgrade.md +2 -2
- data/lib/shakapacker/version.rb +1 -1
- data/package.json +2 -2
- data/shakapacker.gemspec +5 -2
- metadata +5 -235
- data/lib/install/bin/yarn +0 -18
- data/rakelib/release.rake +0 -65
- data/spec/dummy/.browserslistrc +0 -1
- data/spec/dummy/.gitignore +0 -20
- data/spec/dummy/.prettierrc.yaml +0 -4
- data/spec/dummy/Gemfile +0 -61
- data/spec/dummy/Procfile.dev +0 -5
- data/spec/dummy/Procfile.dev-static +0 -9
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
- data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
- data/spec/dummy/app/controllers/application_controller.rb +0 -2
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +0 -9
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/javascript/Globals.d.ts +0 -3
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +0 -25
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +0 -47
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +0 -5
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +0 -7
- data/spec/dummy/app/javascript/packs/application.js +0 -17
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +0 -8
- data/spec/dummy/app/javascript/packs/server-bundle.ts +0 -8
- data/spec/dummy/app/jobs/application_job.rb +0 -7
- data/spec/dummy/app/mailers/application_mailer.rb +0 -4
- data/spec/dummy/app/models/application_record.rb +0 -3
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/app/views/layouts/hello_world.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/spec/dummy/babel.config.js +0 -30
- data/spec/dummy/bin/bundle +0 -114
- data/spec/dummy/bin/dev +0 -30
- data/spec/dummy/bin/dev-static +0 -30
- data/spec/dummy/bin/rails +0 -9
- data/spec/dummy/bin/rake +0 -9
- data/spec/dummy/bin/setup +0 -33
- data/spec/dummy/bin/shakapacker +0 -13
- data/spec/dummy/bin/shakapacker-dev-server +0 -13
- data/spec/dummy/bin/spring +0 -17
- data/spec/dummy/bin/yarn +0 -18
- data/spec/dummy/config/application.rb +0 -35
- data/spec/dummy/config/boot.rb +0 -4
- data/spec/dummy/config/cable.yml +0 -10
- data/spec/dummy/config/credentials.yml.enc +0 -1
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -54
- data/spec/dummy/config/environments/production.rb +0 -106
- data/spec/dummy/config/environments/test.rb +0 -49
- data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/content_security_policy.rb +0 -28
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/react_on_rails.rb +0 -58
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -33
- data/spec/dummy/config/puma.rb +0 -38
- data/spec/dummy/config/routes.rb +0 -6
- data/spec/dummy/config/shakapacker.yml +0 -61
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/config/storage.yml +0 -34
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +0 -34
- data/spec/dummy/config/webpack/clientWebpackConfig.js +0 -15
- data/spec/dummy/config/webpack/commonWebpackConfig.js +0 -17
- data/spec/dummy/config/webpack/development.js +0 -32
- data/spec/dummy/config/webpack/production.js +0 -9
- data/spec/dummy/config/webpack/serverWebpackConfig.js +0 -116
- data/spec/dummy/config/webpack/test.js +0 -7
- data/spec/dummy/config/webpack/webpack.config.js +0 -24
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/db/seeds.rb +0 -7
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +0 -44
- data/spec/dummy/postcss.config.js +0 -12
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +0 -1
- data/spec/dummy/spec/rails_helper.rb +0 -118
- data/spec/dummy/spec/spec_helper.rb +0 -96
- data/spec/dummy/spec/system/hello_world_spec.rb +0 -19
- data/spec/dummy/tsconfig.json +0 -21
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +0 -4696
- data/spec/fixtures/beta_package-lock.v1.json +0 -119
- data/spec/fixtures/beta_package-lock.v2.json +0 -6777
- data/spec/fixtures/beta_package.json +0 -13
- data/spec/fixtures/beta_pnpm-lock.v7.yaml +0 -116
- data/spec/fixtures/beta_pnpm-lock.v8.yaml +0 -2537
- data/spec/fixtures/beta_pnpm-lock.v9.yaml +0 -2885
- data/spec/fixtures/beta_yarn.v1.lock +0 -106
- data/spec/fixtures/beta_yarn.v2.lock +0 -164
- data/spec/fixtures/git_url_package-lock.v1.json +0 -118
- data/spec/fixtures/git_url_package-lock.v2.json +0 -10263
- data/spec/fixtures/git_url_package.json +0 -13
- data/spec/fixtures/git_url_pnpm-lock.v7.yaml +0 -126
- data/spec/fixtures/git_url_pnpm-lock.v8.yaml +0 -3728
- data/spec/fixtures/git_url_pnpm-lock.v9.yaml +0 -4544
- data/spec/fixtures/git_url_yarn.v1.lock +0 -106
- data/spec/fixtures/git_url_yarn.v2.lock +0 -165
- data/spec/fixtures/github_url_package-lock.v1.json +0 -118
- data/spec/fixtures/github_url_package-lock.v2.json +0 -10263
- data/spec/fixtures/github_url_package.json +0 -13
- data/spec/fixtures/github_url_pnpm-lock.v7.yaml +0 -126
- data/spec/fixtures/github_url_pnpm-lock.v8.yaml +0 -3728
- data/spec/fixtures/github_url_pnpm-lock.v9.yaml +0 -4544
- data/spec/fixtures/github_url_yarn.v1.lock +0 -105
- data/spec/fixtures/github_url_yarn.v2.lock +0 -165
- data/spec/fixtures/relative_path_package-lock.v1.json +0 -3468
- data/spec/fixtures/relative_path_package-lock.v2.json +0 -105
- data/spec/fixtures/relative_path_package.json +0 -13
- data/spec/fixtures/relative_path_pnpm-lock.v7.yaml +0 -18
- data/spec/fixtures/relative_path_pnpm-lock.v8.yaml +0 -22
- data/spec/fixtures/relative_path_pnpm-lock.v9.yaml +0 -28
- data/spec/fixtures/relative_path_yarn.v1.lock +0 -104
- data/spec/fixtures/relative_path_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_caret_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_caret_package-lock.v2.json +0 -10264
- data/spec/fixtures/semver_caret_package.json +0 -13
- data/spec/fixtures/semver_caret_pnpm-lock.v7.yaml +0 -117
- data/spec/fixtures/semver_caret_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_caret_pnpm-lock.v9.yaml +0 -4285
- data/spec/fixtures/semver_caret_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_caret_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_exact_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_exact_package-lock.v2.json +0 -6819
- data/spec/fixtures/semver_exact_package.json +0 -13
- data/spec/fixtures/semver_exact_pnpm-lock.v7.yaml +0 -117
- data/spec/fixtures/semver_exact_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_exact_pnpm-lock.v9.yaml +0 -2908
- data/spec/fixtures/semver_exact_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_exact_yarn.v2.lock +0 -165
- data/spec/fixtures/semver_tilde_package-lock.v1.json +0 -119
- data/spec/fixtures/semver_tilde_package-lock.v2.json +0 -6777
- data/spec/fixtures/semver_tilde_package.json +0 -13
- data/spec/fixtures/semver_tilde_pnpm-lock.v7.yaml +0 -116
- data/spec/fixtures/semver_tilde_pnpm-lock.v8.yaml +0 -2558
- data/spec/fixtures/semver_tilde_pnpm-lock.v9.yaml +0 -2885
- data/spec/fixtures/semver_tilde_yarn.v1.lock +0 -106
- data/spec/fixtures/semver_tilde_yarn.v2.lock +0 -164
- data/spec/fixtures/without_package-lock.v1.json +0 -19
- data/spec/fixtures/without_package-lock.v2.json +0 -47
- data/spec/fixtures/without_package.json +0 -13
- data/spec/fixtures/without_pnpm-lock.v7.yaml +0 -23
- data/spec/fixtures/without_pnpm-lock.v8.yaml +0 -27
- data/spec/fixtures/without_pnpm-lock.v9.yaml +0 -34
- data/spec/fixtures/without_yarn.v1.lock +0 -13
- data/spec/fixtures/without_yarn.v2.lock +0 -29
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +0 -4
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +0 -12
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +0 -10
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +0 -2
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +0 -17
- data/spec/generator_specs/e2e_template/files/config/routes.rb +0 -3
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +0 -13
- data/spec/generator_specs/e2e_template/template.rb +0 -29
- data/spec/generator_specs/fake-bin/bun +0 -10
- data/spec/generator_specs/fake-bin/npm +0 -10
- data/spec/generator_specs/fake-bin/pnpm +0 -10
- data/spec/generator_specs/fake-bin/yarn +0 -10
- data/spec/generator_specs/generator_spec.rb +0 -193
- data/spec/mounted_app/Rakefile +0 -4
- data/spec/mounted_app/package.json +0 -1
- data/spec/mounted_app/test/dummy/Rakefile +0 -3
- data/spec/mounted_app/test/dummy/bin/rails +0 -3
- data/spec/mounted_app/test/dummy/bin/rake +0 -3
- data/spec/mounted_app/test/dummy/config/application.rb +0 -10
- data/spec/mounted_app/test/dummy/config/environment.rb +0 -3
- data/spec/mounted_app/test/dummy/config/webpacker.yml +0 -81
- data/spec/mounted_app/test/dummy/config.ru +0 -5
- data/spec/mounted_app/test/dummy/package.json +0 -7
- data/spec/shakapacker/command_spec.rb +0 -134
- data/spec/shakapacker/compiler_spec.rb +0 -57
- data/spec/shakapacker/compiler_strategy_spec.rb +0 -24
- data/spec/shakapacker/configuration_spec.rb +0 -377
- data/spec/shakapacker/dev_server_runner_spec.rb +0 -136
- data/spec/shakapacker/dev_server_spec.rb +0 -118
- data/spec/shakapacker/digest_strategy_spec.rb +0 -59
- data/spec/shakapacker/engine_rake_tasks_spec.rb +0 -50
- data/spec/shakapacker/env_spec.rb +0 -23
- data/spec/shakapacker/helper_spec.rb +0 -243
- data/spec/shakapacker/instance_spec.rb +0 -29
- data/spec/shakapacker/manifest_spec.rb +0 -100
- data/spec/shakapacker/mtime_strategy_spec.rb +0 -55
- data/spec/shakapacker/rake_tasks_spec.rb +0 -85
- data/spec/shakapacker/shakapacker_spec.rb +0 -40
- data/spec/shakapacker/spec_helper_initializer.rb +0 -24
- data/spec/shakapacker/test_app/.gitignore +0 -2
- data/spec/shakapacker/test_app/Rakefile +0 -3
- data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +0 -10
- data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +0 -2
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +0 -4
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +0 -4
- data/spec/shakapacker/test_app/bin/shakapacker +0 -14
- data/spec/shakapacker/test_app/bin/shakapacker-dev-server +0 -14
- data/spec/shakapacker/test_app/config/application.rb +0 -11
- data/spec/shakapacker/test_app/config/environment.rb +0 -4
- data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +0 -1
- data/spec/shakapacker/test_app/config/shakapacker.yml +0 -82
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +0 -83
- data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +0 -11
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +0 -79
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +0 -82
- data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +0 -7
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +0 -84
- data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +0 -18
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/config.ru +0 -5
- data/spec/shakapacker/test_app/package.json +0 -14
- data/spec/shakapacker/test_app/public/packs/manifest.json +0 -58
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/shakapacker/test_app/yarn.lock +0 -11
- data/spec/shakapacker/utils_manager_spec.rb +0 -125
- data/spec/shakapacker/version_checker_spec.rb +0 -1469
- data/spec/shakapacker/webpack_runner_spec.rb +0 -76
- data/spec/spec_helper.rb +0 -100
- data/spec/support/package_json_helpers.rb +0 -19
@@ -1,50 +0,0 @@
|
|
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
|
-
NODE_PACKAGE_MANAGERS.each do |fallback_manager|
|
13
|
-
context "when using package_json with #{fallback_manager} as the manager" do
|
14
|
-
with_package_json_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
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def mounted_app_path
|
31
|
-
File.expand_path("../mounted_app", __dir__)
|
32
|
-
end
|
33
|
-
|
34
|
-
def current_files_in_bin
|
35
|
-
Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
|
36
|
-
end
|
37
|
-
|
38
|
-
def expected_binstub_paths
|
39
|
-
gem_path = File.expand_path("../..", __dir__)
|
40
|
-
Dir.chdir("#{gem_path}/lib/install/bin") do
|
41
|
-
Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def remove_webpack_binstubs
|
46
|
-
expected_binstub_paths.each do |path|
|
47
|
-
File.delete(path) if File.exist?(path)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
RSpec.describe "Env" do
|
4
|
-
it "uses the same env for Rails and Shakapacker" do
|
5
|
-
expect(Shakapacker.env).to eq Rails.env
|
6
|
-
end
|
7
|
-
|
8
|
-
it "uses production env without config" do
|
9
|
-
with_rails_env("foo") do
|
10
|
-
expect(Shakapacker.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(Shakapacker.env).to eq "staging"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it "uses 'production' as default env" do
|
21
|
-
expect(Shakapacker::DEFAULT_ENV).to eq "production"
|
22
|
-
end
|
23
|
-
end
|
@@ -1,243 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
module ActionView::TestCase::Behavior
|
4
|
-
attr_accessor :request
|
5
|
-
|
6
|
-
describe "Shakapacker::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 Shakapacker::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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the 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 the correct tags when 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 the 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 the 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 an 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/main/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 an 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/main/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 the correct tags when 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 the correct tags when passing a 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/main/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 the 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 the 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 the 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 tags" 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 values" 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
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Shakapacker::Instance" do
|
4
|
-
before :each do
|
5
|
-
ENV.delete("SHAKAPACKER_CONFIG")
|
6
|
-
end
|
7
|
-
|
8
|
-
after :each do
|
9
|
-
ENV.delete("SHAKAPACKER_CONFIG")
|
10
|
-
Shakapacker.instance = Shakapacker::Instance.new
|
11
|
-
end
|
12
|
-
|
13
|
-
it "uses the default config path if no env variable defined" do
|
14
|
-
actual_config_path = Rails.root.join("config/shakapacker.yml")
|
15
|
-
expected_config_path = Shakapacker.config.config_path
|
16
|
-
|
17
|
-
expect(expected_config_path).to eq(actual_config_path)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "uses the SHAKAPACKER_CONFIG env variable for the config file path" do
|
21
|
-
ENV["SHAKAPACKER_CONFIG"] = "/some/random/path.yml"
|
22
|
-
Shakapacker.instance = Shakapacker::Instance.new
|
23
|
-
|
24
|
-
actual_config_path = "/some/random/path.yml"
|
25
|
-
expected_config_path = Shakapacker.config.config_path.to_s
|
26
|
-
|
27
|
-
expect(expected_config_path).to eq(actual_config_path)
|
28
|
-
end
|
29
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Shakapacker::Manifest" do
|
4
|
-
let(:manifest_path) { File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s }
|
5
|
-
|
6
|
-
it "#lookup! raises an 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(Shakapacker.config).to receive(:compile?).and_return(false)
|
11
|
-
|
12
|
-
expect {
|
13
|
-
Shakapacker.manifest.lookup!(asset_file)
|
14
|
-
}.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "#lookup! raises an exception for a non-existing asset file with type and without an extension" do
|
18
|
-
asset_file = "calendar"
|
19
|
-
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
20
|
-
|
21
|
-
allow(Shakapacker.config).to receive(:compile?).and_return(false)
|
22
|
-
|
23
|
-
expect {
|
24
|
-
Shakapacker.manifest.lookup!(asset_file, type: :javascript)
|
25
|
-
}.to raise_error(Shakapacker::Manifest::MissingEntryError, /#{expected_error_message}/)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "#lookup! returns the path to the bundled bootstrap.js" do
|
29
|
-
actual = Shakapacker.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 an array of paths to the bundled bootstrap of type javascript" do
|
36
|
-
actual = Shakapacker.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 an array of paths to the bundled bootstrap.js of type javascript" do
|
43
|
-
actual = Shakapacker.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 an array of paths to the bundled 'print/application' without an extension and in a sub-directory" do
|
50
|
-
actual = Shakapacker.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 an array of paths to the bundled 'print/application.css' in a sub-directory" do
|
57
|
-
actual = Shakapacker.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 files" do
|
64
|
-
expect(Shakapacker.manifest.lookup("foo.js")).to be nil
|
65
|
-
end
|
66
|
-
|
67
|
-
it "#lookup_pack_with_chunks returns nil for non-existing asset files" do
|
68
|
-
expect(Shakapacker.manifest.lookup_pack_with_chunks("foo.js")).to be nil
|
69
|
-
end
|
70
|
-
|
71
|
-
it "#lookup returns the path for bootstrap.js" do
|
72
|
-
actual = Shakapacker.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! raises an exception for non-existing asset files" do
|
79
|
-
asset_file = "calendar"
|
80
|
-
|
81
|
-
expected_error_message = "Shakapacker can't find #{asset_file}.js in #{manifest_path}"
|
82
|
-
|
83
|
-
allow(Shakapacker.config).to receive(:compile?).and_return(false)
|
84
|
-
|
85
|
-
expect {
|
86
|
-
Shakapacker.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 an array of paths to bundled js files with 'application' in their name" do
|
91
|
-
actual_application_entrypoints = Shakapacker.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
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Shakapacker::MtimeStrategy" do
|
4
|
-
let(:mtime_strategy) { Shakapacker::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 the 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 the 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 the 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
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "RakeTasks" do
|
4
|
-
TEST_APP_PATH = File.expand_path("./test_app", __dir__)
|
5
|
-
|
6
|
-
it "`rake -T` lists Shakapacker tasks" do
|
7
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake -T` }
|
8
|
-
expect(output).to include "shakapacker"
|
9
|
-
expect(output).to include "shakapacker:check_binstubs"
|
10
|
-
expect(output).to include "shakapacker:check_node"
|
11
|
-
expect(output).to include "shakapacker:check_manager"
|
12
|
-
expect(output).to include "shakapacker:clean"
|
13
|
-
expect(output).to include "shakapacker:clobber"
|
14
|
-
expect(output).to include "shakapacker:compile"
|
15
|
-
expect(output).to include "shakapacker:install"
|
16
|
-
expect(output).to include "shakapacker:verify_install"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "`shakapacker:check_binstubs` doesn't get 'webpack binstub not found' error" do
|
20
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_binstubs 2>&1` }
|
21
|
-
|
22
|
-
expect(output).to_not include "webpack binstub not found."
|
23
|
-
end
|
24
|
-
|
25
|
-
it "`shakapacker:check_node` doesn't get 'shakapacker requires Node.js' error" do
|
26
|
-
output = Dir.chdir(TEST_APP_PATH) { `rake shakapacker:check_node 2>&1` }
|
27
|
-
|
28
|
-
expect(output).to_not include "Shakapacker requires Node.js"
|
29
|
-
end
|
30
|
-
|
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"
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "`shakapacker:check_binstubs`" do
|
40
|
-
def with_temporary_file(file_name)
|
41
|
-
FileUtils.touch(file_name, verbose: false)
|
42
|
-
yield if block_given?
|
43
|
-
ensure
|
44
|
-
FileUtils.rm_f(file_name, verbose: false)
|
45
|
-
end
|
46
|
-
|
47
|
-
before :all do
|
48
|
-
Dir.chdir(TEST_APP_PATH)
|
49
|
-
end
|
50
|
-
|
51
|
-
context "with existing `./bin/shakapacker` and `./bin/shakapacker-dev-server`" do
|
52
|
-
it "passes" do
|
53
|
-
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output("").to_stdout_from_any_process
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "without `./bin/shakapacker`" do
|
58
|
-
before :all do
|
59
|
-
FileUtils.mv("bin/shakapacker", "bin/shakapacker_renamed")
|
60
|
-
end
|
61
|
-
|
62
|
-
after :all do
|
63
|
-
FileUtils.mv("bin/shakapacker_renamed", "bin/shakapacker")
|
64
|
-
end
|
65
|
-
|
66
|
-
it "fails" do
|
67
|
-
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "without `./bin/shakapacker-dev-server`" do
|
72
|
-
before :all do
|
73
|
-
FileUtils.mv("bin/shakapacker-dev-server", "bin/shakapacker-dev-server_renamed")
|
74
|
-
end
|
75
|
-
|
76
|
-
after :all do
|
77
|
-
FileUtils.mv("bin/shakapacker-dev-server_renamed", "bin/shakapacker-dev-server")
|
78
|
-
end
|
79
|
-
|
80
|
-
it "fails" do
|
81
|
-
expect { system("bundle exec rake shakapacker:check_binstubs") }.to output(/Couldn't find shakapacker binstubs!/).to_stdout_from_any_process
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require_relative "spec_helper_initializer"
|
2
|
-
|
3
|
-
describe "Shakapacker" do
|
4
|
-
describe "#inline_css?" do
|
5
|
-
let(:dev_server) { instance_double("Shakapacker::DevServer") }
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
allow(dev_server).to receive(:host).and_return("localhost")
|
9
|
-
allow(dev_server).to receive(:port).and_return("3035")
|
10
|
-
allow(dev_server).to receive(:pretty?).and_return(false)
|
11
|
-
allow(dev_server).to receive(:running?).and_return(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "returns nil when the dev server is disabled" do
|
15
|
-
expect(Shakapacker.inlining_css?).to be nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "returns true when hmr is enabled" do
|
19
|
-
allow(dev_server).to receive(:hmr?).and_return(true)
|
20
|
-
allow(dev_server).to receive(:inline_css?).and_return(true)
|
21
|
-
|
22
|
-
allow(Shakapacker.instance).to receive(:dev_server).and_return(dev_server)
|
23
|
-
|
24
|
-
expect(Shakapacker.inlining_css?).to be true
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns false when hmr is enabled and inline_css is explicitly set to false" do
|
28
|
-
allow(dev_server).to receive(:hmr?).and_return(true)
|
29
|
-
allow(dev_server).to receive(:inline_css?).and_return(false)
|
30
|
-
|
31
|
-
allow(Shakapacker.instance).to receive(:dev_server).and_return(dev_server)
|
32
|
-
|
33
|
-
expect(Shakapacker.inlining_css?).to be false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
it "automatically cleans up app_autoload_paths" do
|
38
|
-
expect($test_app_autoload_paths_in_initializer).to eq []
|
39
|
-
end
|
40
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative "./test_app/config/environment"
|
2
|
-
|
3
|
-
Rails.env = "production"
|
4
|
-
|
5
|
-
Shakapacker.instance = ::Shakapacker::Instance.new
|
6
|
-
|
7
|
-
def reloaded_config
|
8
|
-
Shakapacker.instance.instance_variable_set(:@env, nil)
|
9
|
-
Shakapacker.instance.instance_variable_set(:@config, nil)
|
10
|
-
Shakapacker.instance.instance_variable_set(:@dev_server, nil)
|
11
|
-
Shakapacker.env
|
12
|
-
Shakapacker.config
|
13
|
-
Shakapacker.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
|