shakapacker 6.6.0 → 7.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +4 -8
- data/.github/workflows/dummy.yml +21 -0
- data/.github/workflows/generator.yml +37 -0
- data/.github/workflows/jest.yml +2 -2
- data/.github/workflows/js-lint.yml +2 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby-backward-compatibility.yml +39 -0
- data/.github/workflows/ruby.yml +2 -6
- data/.gitignore +3 -0
- data/CHANGELOG.md +48 -4
- data/CONTRIBUTING.md +78 -22
- data/Gemfile.development_dependencies +1 -1
- data/README.md +115 -88
- data/Rakefile +46 -5
- data/config/shakapacker.yml +1 -0
- data/docs/deployment.md +11 -10
- data/docs/{developing_webpacker.md → developing_shakapacker.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/binstubs.rb +3 -1
- data/lib/install/config/{webpacker.yml → shakapacker.yml} +13 -8
- data/lib/install/config/webpack/webpack.config.js +3 -2
- data/lib/install/template.rb +30 -18
- 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 +87 -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 +29 -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 +26 -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 +27 -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 +25 -2
- 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/{command_spec.rb → backward_compatibility_specs/command_spec.rb} +2 -0
- data/spec/{compiler_spec.rb → backward_compatibility_specs/compiler_spec.rb} +6 -4
- data/spec/{compiler_strategy_spec.rb → backward_compatibility_specs/compiler_strategy_spec.rb} +2 -0
- data/spec/{configuration_spec.rb → backward_compatibility_specs/configuration_spec.rb} +25 -20
- data/spec/{dev_server_runner_spec.rb → backward_compatibility_specs/dev_server_runner_spec.rb} +10 -2
- data/spec/{dev_server_spec.rb → backward_compatibility_specs/dev_server_spec.rb} +4 -2
- data/spec/{digest_strategy_spec.rb → backward_compatibility_specs/digest_strategy_spec.rb} +2 -0
- data/spec/{engine_rake_tasks_spec.rb → backward_compatibility_specs/engine_rake_tasks_spec.rb} +12 -15
- data/spec/{env_spec.rb → backward_compatibility_specs/env_spec.rb} +3 -1
- data/spec/{helper_spec.rb → backward_compatibility_specs/helper_spec.rb} +2 -0
- data/spec/backward_compatibility_specs/instance_spec.rb +31 -0
- data/spec/{manifest_spec.rb → backward_compatibility_specs/manifest_spec.rb} +4 -2
- data/spec/{mtime_strategy_spec.rb → backward_compatibility_specs/mtime_strategy_spec.rb} +2 -0
- data/spec/backward_compatibility_specs/rake_tasks_spec.rb +37 -0
- data/spec/backward_compatibility_specs/spec_helper_initializer.rb +24 -0
- data/spec/{webpack_runner_spec.rb → backward_compatibility_specs/webpack_runner_spec.rb} +3 -1
- data/spec/{webpacker_spec.rb → backward_compatibility_specs/webpacker_spec.rb} +3 -23
- data/spec/backward_compatibility_specs/webpacker_test_app/.gitignore +2 -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/{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/package.json +13 -0
- data/spec/backward_compatibility_specs/webpacker_test_app/tmp/shakapacker/last-compilation-digest-production +1 -0
- data/spec/dummy/.browserslistrc +1 -0
- data/spec/dummy/.gitignore +20 -0
- data/spec/dummy/.prettierrc.yaml +4 -0
- data/spec/dummy/Gemfile +63 -0
- data/spec/dummy/Procfile.dev +5 -0
- data/spec/dummy/Procfile.dev-static +9 -0
- data/spec/dummy/README.md +1 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/hello_world_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/javascript/Globals.d.ts +3 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.module.css +25 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorld.tsx +47 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/HelloWorldServer.tsx +5 -0
- data/spec/dummy/app/javascript/bundles/HelloWorld/components/logo.svg +7 -0
- data/spec/dummy/app/javascript/packs/application.js +17 -0
- data/spec/dummy/app/javascript/packs/hello-world-bundle.ts +8 -0
- data/spec/dummy/app/javascript/packs/server-bundle.ts +8 -0
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/hello_world/index.html.erb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/hello_world.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/babel.config.js +30 -0
- data/spec/dummy/bin/bundle +114 -0
- data/spec/dummy/bin/dev +30 -0
- data/spec/dummy/bin/dev-static +30 -0
- data/spec/dummy/bin/rails +9 -0
- data/spec/dummy/bin/rake +9 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/shakapacker +13 -0
- data/spec/dummy/bin/shakapacker-dev-server +13 -0
- data/spec/dummy/bin/spring +17 -0
- data/spec/dummy/bin/yarn +18 -0
- data/spec/dummy/config/application.rb +32 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +106 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/react_on_rails.rb +58 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +38 -0
- data/spec/dummy/config/routes.rb +6 -0
- data/spec/dummy/config/shakapacker.yml +62 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config/webpack/ServerClientOrBoth.js +34 -0
- data/spec/dummy/config/webpack/clientWebpackConfig.js +15 -0
- data/spec/dummy/config/webpack/commonWebpackConfig.js +18 -0
- data/spec/dummy/config/webpack/development.js +32 -0
- data/spec/dummy/config/webpack/production.js +9 -0
- data/spec/dummy/config/webpack/serverWebpackConfig.js +116 -0
- data/spec/dummy/config/webpack/test.js +7 -0
- data/spec/dummy/config/webpack/webpack.config.js +24 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/package.json +44 -0
- data/spec/dummy/postcss.config.js +12 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- 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 +1 -0
- data/spec/dummy/spec/rails_helper.rb +118 -0
- data/spec/dummy/spec/spec_helper.rb +96 -0
- data/spec/dummy/spec/system/hello_world_spec.rb +19 -0
- data/spec/dummy/tsconfig.json +21 -0
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/dummy/yarn.lock +4697 -0
- data/spec/generator_specs/e2e_template/files/app/controllers/home_controller.rb +4 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/components/App.js +12 -0
- data/spec/generator_specs/e2e_template/files/app/javascript/packs/application.js +10 -0
- data/spec/generator_specs/e2e_template/files/app/views/home/index.html.erb +2 -0
- data/spec/generator_specs/e2e_template/files/app/views/layouts/application.html.erb +17 -0
- data/spec/generator_specs/e2e_template/files/config/routes.rb +3 -0
- data/spec/generator_specs/e2e_template/files/spec/system/test_react_component_renders_spec.rb +13 -0
- data/spec/generator_specs/e2e_template/template.rb +21 -0
- data/spec/generator_specs/generator_spec.rb +169 -0
- data/spec/mounted_app/test/dummy/config/application.rb +1 -1
- data/spec/mounted_app/test/dummy/config/webpacker.yml +3 -3
- data/spec/shakapacker/command_spec.rb +116 -0
- data/spec/shakapacker/compiler_spec.rb +59 -0
- data/spec/shakapacker/compiler_strategy_spec.rb +22 -0
- data/spec/shakapacker/configuration_spec.rb +323 -0
- data/spec/shakapacker/dev_server_runner_spec.rb +72 -0
- data/spec/shakapacker/dev_server_spec.rb +133 -0
- data/spec/shakapacker/digest_strategy_spec.rb +35 -0
- data/spec/shakapacker/engine_rake_tasks_spec.rb +43 -0
- data/spec/shakapacker/env_spec.rb +23 -0
- data/spec/shakapacker/helper_spec.rb +243 -0
- data/spec/shakapacker/instance_spec.rb +31 -0
- data/spec/shakapacker/manifest_spec.rb +100 -0
- data/spec/shakapacker/mtime_strategy_spec.rb +55 -0
- data/spec/shakapacker/rake_tasks_spec.rb +93 -0
- data/spec/shakapacker/shakapacker_spec.rb +41 -0
- data/spec/shakapacker/spec_helper_initializer.rb +24 -0
- data/spec/shakapacker/test_app/.gitignore +2 -0
- data/spec/shakapacker/test_app/Rakefile +3 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/application.js +10 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/generated/something.js +2 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.css +4 -0
- data/spec/shakapacker/test_app/app/javascript/entrypoints/multi_entry.js +4 -0
- data/spec/{test_app/bin/webpacker-dev-server → shakapacker/test_app/bin/shakapacker} +3 -3
- data/spec/{test_app/bin/webpacker → shakapacker/test_app/bin/shakapacker-dev-server} +3 -3
- data/spec/{test_app → shakapacker/test_app}/config/application.rb +1 -1
- data/spec/shakapacker/test_app/config/environment.rb +4 -0
- data/spec/shakapacker/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
- data/spec/shakapacker/test_app/config/shakapacker.yml +82 -0
- data/spec/shakapacker/test_app/config/shakapacker_css_extract_ignore_order_warnings.yml +84 -0
- data/spec/shakapacker/test_app/config/shakapacker_defaults_fallback.yml +11 -0
- data/spec/shakapacker/test_app/config/shakapacker_manifest_path.yml +80 -0
- data/spec/shakapacker/test_app/config/shakapacker_nested_entries.yml +83 -0
- data/spec/shakapacker/test_app/config/shakapacker_no_precompile.yml +7 -0
- data/spec/shakapacker/test_app/config/shakapacker_other_location.yml +85 -0
- data/spec/shakapacker/test_app/config/shakapacker_public_root.yml +18 -0
- data/spec/shakapacker/test_app/config/webpack/webpack.config.js +0 -0
- data/spec/shakapacker/test_app/config.ru +5 -0
- data/spec/shakapacker/test_app/public/packs/manifest.json +58 -0
- data/spec/shakapacker/test_app/some.config.js +0 -0
- data/spec/shakapacker/test_app/yarn.lock +11 -0
- data/spec/{version_checker_spec.rb → shakapacker/version_checker_spec.rb} +25 -24
- data/spec/shakapacker/webpack_runner_spec.rb +55 -0
- data/spec/spec_helper.rb +0 -25
- metadata +253 -72
- data/config/webpacker.yml +0 -1
- data/gemfiles/Gemfile-rails.5.2.x +0 -9
- 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/rake_tasks_spec.rb +0 -32
- data/spec/test_app/config/webpacker_no_precompile.yml +0 -7
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/Rakefile +0 -0
- /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/environment.rb +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/initializers/inspect_autoload_paths.rb +0 -0
- /data/spec/{test_app → 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_manifest_path.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config/webpacker_nested_entries.yml +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/config.ru +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/public/packs/manifest.json +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/some.config.js +0 -0
- /data/spec/{test_app → backward_compatibility_specs/webpacker_test_app}/yarn.lock +0 -0
- /data/spec/{test_app → shakapacker/test_app}/package.json +0 -0
@@ -0,0 +1,323 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "Shakapacker::Configuration" do
|
4
|
+
ROOT_PATH = Pathname.new(File.expand_path("./test_app", __dir__))
|
5
|
+
|
6
|
+
context "with standard shakapacker.yml" do
|
7
|
+
let(:config) do
|
8
|
+
Shakapacker::Configuration.new(
|
9
|
+
root_path: ROOT_PATH,
|
10
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
|
11
|
+
env: "production"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "#source_path returns correct path" do
|
16
|
+
source_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript").to_s
|
17
|
+
expect(config.source_path.to_s).to eq source_path
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#source_entry_path returns correct path" do
|
21
|
+
source_entry_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "entrypoints").to_s
|
22
|
+
expect(config.source_entry_path.to_s).to eq source_entry_path
|
23
|
+
end
|
24
|
+
|
25
|
+
it "#public_root_path returns correct path" do
|
26
|
+
public_root_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public").to_s
|
27
|
+
expect(config.public_path.to_s).to eq public_root_path
|
28
|
+
end
|
29
|
+
|
30
|
+
it "#public_output_path returns correct path" do
|
31
|
+
public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs").to_s
|
32
|
+
expect(config.public_output_path.to_s).to eq public_output_path
|
33
|
+
end
|
34
|
+
|
35
|
+
it "#public_manifest_path returns correct path" do
|
36
|
+
public_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
|
37
|
+
expect(config.public_manifest_path.to_s).to eq public_manifest_path
|
38
|
+
end
|
39
|
+
|
40
|
+
it "#manifest_path returns correct path" do
|
41
|
+
manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/public/packs", "manifest.json").to_s
|
42
|
+
expect(config.manifest_path.to_s).to eq manifest_path
|
43
|
+
end
|
44
|
+
|
45
|
+
it "#cache_path returns correct path" do
|
46
|
+
cache_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/tmp/shakapacker").to_s
|
47
|
+
expect(config.cache_path.to_s).to eq cache_path
|
48
|
+
end
|
49
|
+
|
50
|
+
it "#additional_paths returns correct path" do
|
51
|
+
expect(config.additional_paths).to eq ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#cache_manifest?" do
|
55
|
+
it "returns true in production environment" do
|
56
|
+
expect(config.cache_manifest?).to be true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns false in developemnt environemnt" do
|
60
|
+
with_rails_env("development") do
|
61
|
+
expect(Shakapacker.config.cache_manifest?).to be false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns false in test environment" do
|
66
|
+
with_rails_env("test") do
|
67
|
+
expect(Shakapacker.config.cache_manifest?).to be false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#compile?" do
|
73
|
+
it "returns false in production environment" do
|
74
|
+
expect(config.compile?).to be false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns true in developemnt environemnt" do
|
78
|
+
with_rails_env("development") do
|
79
|
+
expect(Shakapacker.config.compile?).to be true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns true in test environemnt" do
|
84
|
+
with_rails_env("test") do
|
85
|
+
expect(Shakapacker.config.compile?).to be true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "#nested_entries?" do
|
91
|
+
it "returns false in production environment" do
|
92
|
+
expect(config.nested_entries?).to be false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "returns false in development environment" do
|
96
|
+
with_rails_env("development") do
|
97
|
+
expect(Shakapacker.config.nested_entries?).to be false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns false in test environment" do
|
102
|
+
with_rails_env("test") do
|
103
|
+
expect(Shakapacker.config.nested_entries?).to be false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#ensure_consistent_versioning?" do
|
109
|
+
it "returns false in production environment" do
|
110
|
+
expect(config.ensure_consistent_versioning?).to be false
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns true in development environment" do
|
114
|
+
with_rails_env("development") do
|
115
|
+
expect(Shakapacker.config.ensure_consistent_versioning?).to be true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it "returns false in test environment" do
|
120
|
+
with_rails_env("test") do
|
121
|
+
expect(Shakapacker.config.ensure_consistent_versioning?).to be false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#shakapacker_precompile?" do
|
127
|
+
before :each do
|
128
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
129
|
+
end
|
130
|
+
|
131
|
+
subject { config.shakapacker_precompile? }
|
132
|
+
|
133
|
+
it "returns true when SHAKAPACKER_PRECOMPILE is unset" do
|
134
|
+
is_expected.to be true
|
135
|
+
end
|
136
|
+
|
137
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to no" do
|
138
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "no"
|
139
|
+
is_expected.to be false
|
140
|
+
end
|
141
|
+
|
142
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to yes" do
|
143
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "yes"
|
144
|
+
is_expected.to be true
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to false" do
|
148
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "false"
|
149
|
+
is_expected.to be false
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to true" do
|
153
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "true"
|
154
|
+
is_expected.to be true
|
155
|
+
end
|
156
|
+
|
157
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to n" do
|
158
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "n"
|
159
|
+
is_expected.to be false
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to y" do
|
163
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "y"
|
164
|
+
is_expected.to be true
|
165
|
+
end
|
166
|
+
|
167
|
+
it "returns false when SHAKAPACKER_PRECOMPILE sets to f" do
|
168
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "f"
|
169
|
+
is_expected.to be false
|
170
|
+
end
|
171
|
+
|
172
|
+
it "returns true when SHAKAPACKER_PRECOMPILE sets to t" do
|
173
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "t"
|
174
|
+
is_expected.to be true
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "with shakapacker config file containing public_output_path entry" do
|
180
|
+
config = Shakapacker::Configuration.new(
|
181
|
+
root_path: ROOT_PATH,
|
182
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_public_root.yml", __dir__)),
|
183
|
+
env: "production"
|
184
|
+
)
|
185
|
+
|
186
|
+
it "#public_output_path returns correct path" do
|
187
|
+
expected_public_output_path = File.expand_path File.join(File.dirname(__FILE__), "./public/packs").to_s
|
188
|
+
expect(config.public_output_path.to_s).to eq expected_public_output_path
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "with shakapacker config file containing manifext_path entry" do
|
193
|
+
config = Shakapacker::Configuration.new(
|
194
|
+
root_path: ROOT_PATH,
|
195
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_manifest_path.yml", __dir__)),
|
196
|
+
env: "production"
|
197
|
+
)
|
198
|
+
|
199
|
+
it "#manifest_path returns correct expected value" do
|
200
|
+
expected_manifest_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/app/javascript", "manifest.json").to_s
|
201
|
+
expect(config.manifest_path.to_s).to eq expected_manifest_path
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "with shakapacker_precompile entry set to false" do
|
206
|
+
describe "#shakapacker_precompile?" do
|
207
|
+
before :each do
|
208
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
209
|
+
end
|
210
|
+
|
211
|
+
let(:config) {
|
212
|
+
Shakapacker::Configuration.new(
|
213
|
+
root_path: ROOT_PATH,
|
214
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_no_precompile.yml", __dir__)),
|
215
|
+
env: "production"
|
216
|
+
)
|
217
|
+
}
|
218
|
+
|
219
|
+
subject { config.shakapacker_precompile? }
|
220
|
+
|
221
|
+
it "returns false with unset SHAKAPACKER_PRECOMPILE" do
|
222
|
+
expect(subject).to be false
|
223
|
+
end
|
224
|
+
|
225
|
+
it "returns true with SHAKAPACKER_PRECOMPILE set to true" do
|
226
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = "true"
|
227
|
+
expect(subject).to be true
|
228
|
+
end
|
229
|
+
|
230
|
+
it "returns false with SHAKAPACKER_PRECOMPILE set to nil" do
|
231
|
+
ENV["SHAKAPACKER_PRECOMPILE"] = nil
|
232
|
+
expect(subject).to be false
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "with shakapacker config file containing invalid path" do
|
238
|
+
config = Shakapacker::Configuration.new(
|
239
|
+
root_path: ROOT_PATH,
|
240
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/invalid_path.yml", __dir__)),
|
241
|
+
env: "default"
|
242
|
+
)
|
243
|
+
|
244
|
+
it "#shakapacker_precompile? returns false" do
|
245
|
+
expect(config.shakapacker_precompile?).to be false
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context "with shakapacker config file with defaults fallback" do
|
250
|
+
let(:config) do
|
251
|
+
Shakapacker::Configuration.new(
|
252
|
+
root_path: ROOT_PATH,
|
253
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
|
254
|
+
env: "default"
|
255
|
+
)
|
256
|
+
end
|
257
|
+
|
258
|
+
it "#cache_manifest? falls back to 'default' config from bundled file" do
|
259
|
+
expect(config.cache_manifest?).to be false
|
260
|
+
end
|
261
|
+
|
262
|
+
it "#shakapacker_precompile? uses 'default' config from custom file" do
|
263
|
+
expect(config.shakapacker_precompile?).to be false
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "falls back to bundled production config for custom environments" do
|
268
|
+
let(:config) do
|
269
|
+
Shakapacker::Configuration.new(
|
270
|
+
root_path: ROOT_PATH,
|
271
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker_defaults_fallback.yml", __dir__)),
|
272
|
+
env: "staging"
|
273
|
+
)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "#cache_manifest? fall back to 'production' config from bundled file" do
|
277
|
+
expect(config.cache_manifest?).to be true
|
278
|
+
end
|
279
|
+
it "#shakapacker_precompile? use 'staging' config from custom file" do
|
280
|
+
expect(config.shakapacker_precompile?).to be false
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context "#source_entry_path" do
|
285
|
+
let(:config) do
|
286
|
+
Shakapacker::Configuration.new(
|
287
|
+
root_path: ROOT_PATH,
|
288
|
+
config_path: Pathname.new(File.expand_path("./test_app/config/shakapacker.yml", __dir__)),
|
289
|
+
env: "production"
|
290
|
+
)
|
291
|
+
end
|
292
|
+
|
293
|
+
it "returns correct path with source_entry_path starting with 'extra_path'" do
|
294
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
295
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("extra_path")
|
296
|
+
|
297
|
+
actual = config.source_entry_path.to_s
|
298
|
+
expected = "#{config.source_path.to_s}/extra_path"
|
299
|
+
|
300
|
+
expect(actual).to eq(expected)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "returns correct path with source_entry_path starting with /" do
|
304
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
305
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("/")
|
306
|
+
|
307
|
+
actual = config.source_entry_path.to_s
|
308
|
+
expected = config.source_path.to_s
|
309
|
+
|
310
|
+
expect(actual).to eq(expected)
|
311
|
+
end
|
312
|
+
|
313
|
+
it "returns correct path with source_entry_path starting with /extra_path" do
|
314
|
+
allow(config).to receive(:fetch).with(:source_path).and_return("the_source_path")
|
315
|
+
allow(config).to receive(:fetch).with(:source_entry_path).and_return("/extra_path")
|
316
|
+
|
317
|
+
actual = config.source_entry_path.to_s
|
318
|
+
expected = "#{config.source_path.to_s}/extra_path"
|
319
|
+
|
320
|
+
expect(actual).to eq(expected)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
require "shakapacker/dev_server_runner"
|
3
|
+
|
4
|
+
describe "DevServerRunner" do
|
5
|
+
before do
|
6
|
+
@original_node_env, ENV["NODE_ENV"] = ENV["NODE_ENV"], "development"
|
7
|
+
@original_rails_env, ENV["RAILS_ENV"] = ENV["RAILS_ENV"], "development"
|
8
|
+
@original_shakapacker_config = ENV["SHAKAPACKER_CONFIG"]
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
ENV["NODE_ENV"] = @original_node_env
|
13
|
+
ENV["RAILS_ENV"] = @original_rails_env
|
14
|
+
ENV["SHAKAPACKER_CONFIG"] = @original_shakapacker_config
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:test_app_path) { File.expand_path("./test_app", __dir__) }
|
18
|
+
|
19
|
+
it "run cmd via node modules" do
|
20
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
21
|
+
verify_command(cmd, use_node_modules: true)
|
22
|
+
end
|
23
|
+
it "run cmd via yarn" do
|
24
|
+
cmd = ["yarn", "webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
25
|
+
verify_command(cmd, use_node_modules: false)
|
26
|
+
end
|
27
|
+
it "run cmd argv" do
|
28
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--quiet"]
|
29
|
+
verify_command(cmd, argv: (["--quiet"]))
|
30
|
+
end
|
31
|
+
it "run cmd argv with https" do
|
32
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js", "--https"]
|
33
|
+
|
34
|
+
dev_server = double()
|
35
|
+
allow(dev_server).to receive(:host).and_return("localhost")
|
36
|
+
allow(dev_server).to receive(:port).and_return("3035")
|
37
|
+
allow(dev_server).to receive(:pretty?).and_return(false)
|
38
|
+
allow(dev_server).to receive(:https?).and_return(true)
|
39
|
+
allow(dev_server).to receive(:hmr?).and_return(false)
|
40
|
+
|
41
|
+
allow(Shakapacker::DevServer).to receive(:new) do
|
42
|
+
verify_command(cmd, argv: (["--https"]))
|
43
|
+
end.and_return(dev_server)
|
44
|
+
end
|
45
|
+
it "accepts environment variables" do
|
46
|
+
cmd = ["#{test_app_path}/node_modules/.bin/webpack", "serve", "--config", "#{test_app_path}/config/webpack/webpack.config.js"]
|
47
|
+
env = Shakapacker::Compiler.env.dup
|
48
|
+
ENV["SHAKAPACKER_CONFIG"] = env["SHAKAPACKER_CONFIG"] = "#{test_app_path}/config/shakapacker_other_location.yml"
|
49
|
+
env["WEBPACK_SERVE"] = "true"
|
50
|
+
verify_command(cmd, env: env)
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def verify_command(cmd, use_node_modules: true, argv: [], env: Shakapacker::Compiler.env)
|
56
|
+
cwd = Dir.pwd
|
57
|
+
Dir.chdir(test_app_path)
|
58
|
+
klass = Shakapacker::DevServerRunner
|
59
|
+
instance = klass.new(argv)
|
60
|
+
|
61
|
+
allow(klass).to receive(:new).and_return(instance)
|
62
|
+
allow(instance).to receive(:node_modules_bin_exist?).and_return(use_node_modules)
|
63
|
+
allow(Kernel).to receive(:exec).with(env, *cmd)
|
64
|
+
|
65
|
+
klass.run(argv)
|
66
|
+
|
67
|
+
expect(Kernel).to have_received(:exec).with(env, *cmd)
|
68
|
+
|
69
|
+
ensure
|
70
|
+
Dir.chdir(cwd)
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative "spec_helper_initializer"
|
2
|
+
|
3
|
+
describe "DevServer" do
|
4
|
+
it "doesn't run by default" do
|
5
|
+
expect(Shakapacker.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(Shakapacker.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(Shakapacker.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(Shakapacker.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(Shakapacker.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(Shakapacker.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(Shakapacker.dev_server.pretty?).to be false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "users SHAKAPACKER_DEV_SERVER for DEFAULT_ENV_PREFIX" do
|
45
|
+
expect(Shakapacker::DevServer::DEFAULT_ENV_PREFIX).to eq "SHAKAPACKER_DEV_SERVER"
|
46
|
+
end
|
47
|
+
|
48
|
+
context "#protocol in development environment" do
|
49
|
+
let(:dev_server) { Shakapacker.dev_server }
|
50
|
+
|
51
|
+
it "returns `http` by default (with unset `server` and `https`)" do
|
52
|
+
with_rails_env("development") do
|
53
|
+
expect(dev_server.protocol).to eq "http"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns `https` when `server` is set to `https`" do
|
58
|
+
expect(dev_server).to receive(:server).and_return("https")
|
59
|
+
|
60
|
+
with_rails_env("development") do
|
61
|
+
expect(dev_server.protocol).to eq "https"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns `https` with unset `server` and `https` set to `true`" do
|
66
|
+
expect(dev_server).to receive(:server).and_return("http")
|
67
|
+
expect(dev_server).to receive(:https?).and_return(true)
|
68
|
+
|
69
|
+
with_rails_env("development") do
|
70
|
+
expect(dev_server.protocol).to eq "https"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "#server in development environment" do
|
76
|
+
let(:dev_server) { Shakapacker.dev_server }
|
77
|
+
|
78
|
+
it "returns `http` when unset" do
|
79
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return(nil)
|
80
|
+
|
81
|
+
with_rails_env("development") do
|
82
|
+
expect(dev_server.server).to eq "http"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "returns `http` when set to `https`" do
|
87
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return("http")
|
88
|
+
|
89
|
+
with_rails_env("development") do
|
90
|
+
expect(dev_server.server).to eq "http"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "returns `http` when set to a hash with `type: http`" do
|
95
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return({
|
96
|
+
type: "http",
|
97
|
+
options: {}
|
98
|
+
})
|
99
|
+
|
100
|
+
with_rails_env("development") do
|
101
|
+
expect(dev_server.server).to eq "http"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it "returns `https` when set to `https`" do
|
106
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return("https")
|
107
|
+
|
108
|
+
with_rails_env("development") do
|
109
|
+
expect(dev_server.server).to eq "https"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it "returns `https` when set to a hash with `type: https`" do
|
114
|
+
expect(dev_server).to receive(:fetch).with(:server).and_return({
|
115
|
+
type: "https",
|
116
|
+
options: {}
|
117
|
+
})
|
118
|
+
|
119
|
+
with_rails_env("development") do
|
120
|
+
expect(dev_server.server).to eq "https"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it "returns `http` when set to any value except `http` and `https`" do
|
125
|
+
expect(dev_server).to receive(:fetch).twice.with(:server).and_return("other-than-https")
|
126
|
+
|
127
|
+
with_rails_env("development") do
|
128
|
+
expect(dev_server.server).to eq "http"
|
129
|
+
expect { dev_server.server }.to output(/WARNING/).to_stdout
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
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 = Shakapacker::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-#{Shakapacker.env}"
|
33
|
+
expect(actual_path).to eq expected_path
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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:shakapacker task successfully" do
|
13
|
+
output = Dir.chdir(mounted_app_path) { `rake -T` }
|
14
|
+
expect(output).to include "app:shakapacker"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "binstubs adds only expected files to bin directory" do
|
18
|
+
Dir.chdir(mounted_app_path) { `bundle exec rake app:shakapacker:binstubs` }
|
19
|
+
expected_binstub_paths.each { |path| expect(File.exist?(path)).to be true }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def mounted_app_path
|
24
|
+
File.expand_path("../mounted_app", __dir__)
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_files_in_bin
|
28
|
+
Dir.glob("#{mounted_app_path}/test/dummy/bin/*")
|
29
|
+
end
|
30
|
+
|
31
|
+
def expected_binstub_paths
|
32
|
+
gem_path = File.expand_path("../..", __dir__)
|
33
|
+
Dir.chdir("#{gem_path}/lib/install/bin") do
|
34
|
+
Dir.glob("*").map { |file| "#{mounted_app_path}/test/dummy/bin/#{file}" }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_webpack_binstubs
|
39
|
+
expected_binstub_paths.each do |path|
|
40
|
+
File.delete(path) if File.exist?(path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|