Skip to content

Commit 50bd90b

Browse files
committed
Basic tests for a mounted application
This sets up a barebones mounted Rails engine so that tests can be performed against it. This follows a similar approach to the other rake tasks test and thus doesn't intend to be too exhaustive in what is testing and is mostly a cursory test that one of the tasks does perform differently in a mounted Rails engine context.
1 parent 466caa8 commit 50bd90b

11 files changed

+153
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.bundle
22
/pkg
3+
/test/mounted_app/test/dummy/log
34
/test/test_app/log
45
node_modules
56
.byebug_history

test/engine_rake_tasks_test.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require "test_helper"
2+
3+
class EngineRakeTasksTest < Minitest::Test
4+
def setup
5+
remove_webpack_binstubs
6+
end
7+
8+
def teardown
9+
remove_webpack_binstubs
10+
end
11+
12+
def test_task_mounted
13+
output = Dir.chdir(mounted_app_path) { `rake -T` }
14+
assert_includes output, "app:webpacker"
15+
end
16+
17+
def test_binstubs
18+
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` }
19+
webpack_binstub_paths.each { |path| assert File.exist?(path) }
20+
end
21+
22+
private
23+
def mounted_app_path
24+
File.expand_path("mounted_app", __dir__)
25+
end
26+
27+
def webpack_binstub_paths
28+
[
29+
"#{mounted_app_path}/test/dummy/bin/webpack",
30+
"#{mounted_app_path}/test/dummy/bin/webpack-dev-server",
31+
]
32+
end
33+
34+
def remove_webpack_binstubs
35+
webpack_binstub_paths.each do |path|
36+
File.delete(path) if File.exist?(path)
37+
end
38+
end
39+
end

test/mounted_app/Rakefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require "bundler/setup"
2+
3+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4+
load "rails/tasks/engine.rake"

test/mounted_app/test/dummy/Rakefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative "config/application"
2+
3+
Rails.application.load_tasks

test/mounted_app/test/dummy/bin/rails

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
APP_PATH = File.expand_path("../config/application", __dir__)
3+
require "rails/commands"

test/mounted_app/test/dummy/bin/rake

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env ruby
2+
require "rake"
3+
Rake.application.run

test/mounted_app/test/dummy/config.ru

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file allows the `Rails.root` to be correctly determined.
2+
3+
require_relative "config/environment"
4+
5+
run Rails.application
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "action_controller/railtie"
2+
require "action_view/railtie"
3+
require "webpacker"
4+
5+
module TestDummyApp
6+
class Application < Rails::Application
7+
config.secret_key_base = "abcdef"
8+
config.eager_load = true
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative "application"
2+
3+
Rails.application.initialize!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Note: You must restart bin/webpack-dev-server for changes to take effect
2+
3+
default: &default
4+
source_path: app/javascript
5+
source_entry_path: packs
6+
public_output_path: packs
7+
cache_path: tmp/cache/webpacker
8+
9+
# Additional paths webpack should lookup modules
10+
# ['app/assets', 'engine/foo/app/assets']
11+
resolved_paths:
12+
- app/assets
13+
- /etc/yarn
14+
15+
# Reload manifest.json on all requests so we reload latest compiled packs
16+
cache_manifest: false
17+
18+
extensions:
19+
- .js
20+
- .sass
21+
- .scss
22+
- .css
23+
- .module.sass
24+
- .module.scss
25+
- .module.css
26+
- .png
27+
- .svg
28+
- .gif
29+
- .jpeg
30+
- .jpg
31+
32+
development:
33+
<<: *default
34+
compile: true
35+
36+
# Reference: https://webpack.js.org/configuration/dev-server/
37+
dev_server:
38+
https: false
39+
host: localhost
40+
port: 3035
41+
public: localhost:3035
42+
hmr: false
43+
# Inline should be set to true if using HMR
44+
inline: true
45+
overlay: true
46+
disable_host_check: true
47+
use_local_ip: false
48+
49+
test:
50+
<<: *default
51+
compile: true
52+
53+
# Compile test packs to a separate directory
54+
public_output_path: packs-test
55+
56+
production:
57+
<<: *default
58+
59+
# Production depends on precompilation of packs prior to booting for performance.
60+
compile: false
61+
62+
# Cache manifest.json for performance
63+
cache_manifest: true
64+
65+
staging:
66+
<<: *default
67+
68+
# Production depends on precompilation of packs prior to booting for performance.
69+
compile: false
70+
71+
# Cache manifest.json for performance
72+
cache_manifest: true
73+
74+
# Compile staging packs to a separate directory
75+
public_output_path: packs-staging
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"@rails/webpacker": "file:../../../../"
5+
},
6+
"license": "MIT"
7+
}

0 commit comments

Comments
 (0)