-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
11 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/.bundle | ||
/pkg | ||
/test/mounted_app/test/dummy/log | ||
/test/test_app/log | ||
node_modules | ||
.byebug_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "test_helper" | ||
|
||
class EngineRakeTasksTest < Minitest::Test | ||
def setup | ||
remove_webpack_binstubs | ||
end | ||
|
||
def teardown | ||
remove_webpack_binstubs | ||
end | ||
|
||
def test_task_mounted | ||
output = Dir.chdir(mounted_app_path) { `rake -T` } | ||
assert_includes output, "app:webpacker" | ||
end | ||
|
||
def test_binstubs | ||
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` } | ||
webpack_binstub_paths.each { |path| assert File.exist?(path) } | ||
end | ||
|
||
private | ||
def mounted_app_path | ||
File.expand_path("mounted_app", __dir__) | ||
end | ||
|
||
def webpack_binstub_paths | ||
[ | ||
"#{mounted_app_path}/test/dummy/bin/webpack", | ||
"#{mounted_app_path}/test/dummy/bin/webpack-dev-server", | ||
] | ||
end | ||
|
||
def remove_webpack_binstubs | ||
webpack_binstub_paths.each do |path| | ||
File.delete(path) if File.exist?(path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "bundler/setup" | ||
|
||
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) | ||
load "rails/tasks/engine.rake" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require_relative "config/application" | ||
|
||
Rails.application.load_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
require "rails/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require 'rake' | ||
Rake.application.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file allows the `Rails.root` to be correctly determined. | ||
|
||
require_relative "config/environment" | ||
|
||
run Rails.application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "action_controller/railtie" | ||
require "action_view/railtie" | ||
require "webpacker" | ||
|
||
module TestDummyApp | ||
class Application < Rails::Application | ||
config.secret_key_base = "abcdef" | ||
config.eager_load = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require_relative "application" | ||
|
||
Rails.application.initialize! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default | ||
source_path: app/javascript | ||
source_entry_path: packs | ||
public_output_path: packs | ||
cache_path: tmp/cache/webpacker | ||
|
||
# Additional paths webpack should lookup modules | ||
# ['app/assets', 'engine/foo/app/assets'] | ||
resolved_paths: | ||
- app/assets | ||
- /etc/yarn | ||
|
||
# Reload manifest.json on all requests so we reload latest compiled packs | ||
cache_manifest: false | ||
|
||
extensions: | ||
- .js | ||
- .sass | ||
- .scss | ||
- .css | ||
- .module.sass | ||
- .module.scss | ||
- .module.css | ||
- .png | ||
- .svg | ||
- .gif | ||
- .jpeg | ||
- .jpg | ||
|
||
development: | ||
<<: *default | ||
compile: true | ||
|
||
# Reference: https://webpack.js.org/configuration/dev-server/ | ||
dev_server: | ||
https: false | ||
host: localhost | ||
port: 3035 | ||
public: localhost:3035 | ||
hmr: false | ||
# Inline should be set to true if using HMR | ||
inline: true | ||
overlay: true | ||
disable_host_check: true | ||
use_local_ip: false | ||
|
||
test: | ||
<<: *default | ||
compile: true | ||
|
||
# Compile test packs to a separate directory | ||
public_output_path: packs-test | ||
|
||
production: | ||
<<: *default | ||
|
||
# Production depends on precompilation of packs prior to booting for performance. | ||
compile: false | ||
|
||
# Cache manifest.json for performance | ||
cache_manifest: true | ||
|
||
staging: | ||
<<: *default | ||
|
||
# Production depends on precompilation of packs prior to booting for performance. | ||
compile: false | ||
|
||
# Cache manifest.json for performance | ||
cache_manifest: true | ||
|
||
# Compile staging packs to a separate directory | ||
public_output_path: packs-staging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"@rails/webpacker": "file:../../../../" | ||
}, | ||
"license": "MIT" | ||
} |