Skip to content

Commit

Permalink
Basic tests for a mounted application
Browse files Browse the repository at this point in the history
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
kevindew committed Oct 3, 2018
1 parent 8580f9a commit 26abb1d
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
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
Expand Down
39 changes: 39 additions & 0 deletions test/engine_rake_tasks_test.rb
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
4 changes: 4 additions & 0 deletions test/mounted_app/Rakefile
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"
3 changes: 3 additions & 0 deletions test/mounted_app/test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative "config/application"

Rails.application.load_tasks
3 changes: 3 additions & 0 deletions test/mounted_app/test/dummy/bin/rails
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"
3 changes: 3 additions & 0 deletions test/mounted_app/test/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
require "rake"
Rake.application.run
5 changes: 5 additions & 0 deletions test/mounted_app/test/dummy/config.ru
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
10 changes: 10 additions & 0 deletions test/mounted_app/test/dummy/config/application.rb
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
3 changes: 3 additions & 0 deletions test/mounted_app/test/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative "application"

Rails.application.initialize!
75 changes: 75 additions & 0 deletions test/mounted_app/test/dummy/config/webpacker.yml
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
7 changes: 7 additions & 0 deletions test/mounted_app/test/dummy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"private": true,
"dependencies": {
"@rails/webpacker": "file:../../../../"
},
"license": "MIT"
}

0 comments on commit 26abb1d

Please sign in to comment.