Skip to content

Commit

Permalink
Fix tests and update the test app to Rails 5.1 / Webpacker 2
Browse files Browse the repository at this point in the history
* update example app to Rails 5.1
* update example app to Webpacker 2
* added rake tasks to run yarn and webpacker in the example app before tests (related to #16)
  • Loading branch information
renchap committed May 27, 2017
1 parent bf9b079 commit 20ac97a
Show file tree
Hide file tree
Showing 32 changed files with 5,270 additions and 3,240 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules/
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
Expand All @@ -14,5 +13,6 @@ node_modules/
test/example_app/log/*
test/example_app/tmp/*
test/example_app/public/packs
test/example_app/public/packs-test

.rvmrc
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
source "https://rubygems.org"

gem "rubocop", ">= 0.47", require: false
gem "rails", github: "rails/rails"
gem "arel", github: "rails/arel"
gem "webpacker", github: "rails/webpacker"
gem "rails", "~> 5.1.1"
gem "webpacker", "~> 2.0.0"

# Specify your gem's dependencies in webpacker-react.gemspec
gemspec
159 changes: 159 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
PATH
remote: .
specs:
webpacker-react (0.2.0)
webpacker

GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.1)
actionpack (= 5.1.1)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.1)
actionview (= 5.1.1)
activesupport (= 5.1.1)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.1)
activesupport (= 5.1.1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.1)
activesupport (= 5.1.1)
globalid (>= 0.3.6)
activemodel (5.1.1)
activesupport (= 5.1.1)
activerecord (5.1.1)
activemodel (= 5.1.1)
activesupport (= 5.1.1)
arel (~> 8.0)
activesupport (5.1.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
arel (8.0.0)
ast (2.3.0)
builder (3.2.3)
capybara (2.12.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
concurrent-ruby (1.0.5)
erubi (1.6.0)
globalid (0.4.0)
activesupport (>= 4.2.0)
i18n (0.8.1)
loofah (2.0.3)
nokogiri (>= 1.5.9)
mail (2.6.5)
mime-types (>= 1.16, < 4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
multi_json (1.12.1)
nio4r (2.0.0)
nokogiri (1.7.0.1)
mini_portile2 (~> 2.1.0)
parser (2.4.0.0)
ast (~> 2.2)
poltergeist (1.13.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
powerpack (0.1.1)
public_suffix (2.0.5)
rack (2.0.1)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.1.1)
actioncable (= 5.1.1)
actionmailer (= 5.1.1)
actionpack (= 5.1.1)
actionview (= 5.1.1)
activejob (= 5.1.1)
activemodel (= 5.1.1)
activerecord (= 5.1.1)
activesupport (= 5.1.1)
bundler (>= 1.3.0, < 2.0)
railties (= 5.1.1)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.1)
actionpack (= 5.1.1)
activesupport (= 5.1.1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.2.1)
rake (10.5.0)
rubocop (0.47.1)
parser (>= 2.3.3.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.19.4)
thread_safe (0.3.6)
tzinfo (1.2.3)
thread_safe (~> 0.1)
unicode-display_width (1.1.3)
webpacker (2.0)
activesupport (>= 4.2)
multi_json (~> 1.2)
railties (>= 4.2)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.13)
capybara
minitest (~> 5.0)
poltergeist
rails (~> 5.1.1)
rake (~> 10.0)
rubocop (>= 0.47)
webpacker (~> 2.0.0)
webpacker-react!

BUNDLED WITH
1.15.0
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,15 @@ After launching `./bin/webpack-watcher` and `./bin/rails server` in your example
## Testing
Make sure you run first:
If you changed the local javascript package, first ensure it is build (see above).
```sh
$ test/example_app/bin/yarn
$ test/example_app/bin/webpack
```
And optionally:
```sh
$ cd test/example_app/vendor/
$ yarn link "webpacker-react"
```
Finally, run the test suite:
To run the test suite:
```sh
$ rake test
```
If you change the javascript code, please ensure there are no style errors:
If you change the javascript code, please ensure there are no style errors before committing:
```sh
$ cd javascript/webpacker_react-npm-module/
Expand Down
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.verbose = true
end

task default: :test

Dir["lib/tasks/*.rake"].each { |f| load f }
18 changes: 8 additions & 10 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
machine:
node:
version: 6.1.0
checkout:
version: 7.9.0
compile:
post:
- yarn:
pwd: javascript/webpacker_react-npm-module
- yarn:
pwd: javascript/webpacker_react-npm-module/dist
- yarn link:
pwd: javascript/webpacker_react-npm-module/dist
compile:
override:
- test/example_app/bin/yarn
- yarn link webpacker-react:
pwd: test/example_app/vendor
- test/example_app/bin/webpack
dependancies:
post:
- yarn:
pwd: app/example_app
cache_directories:
- ~/.cache/yarn
test:
pre:
- yarn lint:
Expand Down
7 changes: 7 additions & 0 deletions lib/tasks/disable_webpacker_checks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# webpacker:check_webpack_binstubs is looking for binstubs
# in the gem root directory. We need to disable it for our
# tests, as it tries to check they exist when loading the
# example app

task "webpacker:check_webpack_binstubs"
Rake::Task["webpacker:check_webpack_binstubs"].clear
15 changes: 15 additions & 0 deletions lib/tasks/example_app.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "English"

namespace :example_app do
desc "Runs yarn in test/example_app"
task :yarn do
sh "cd test/example_app && yarn"
end

desc "Runs webpack in test/example_app"
task webpack: :yarn do
sh "cd test/example_app && NODE_ENV=test ./bin/webpack"
end
end

Rake::Task["test"].enhance ["example_app:webpack"]
25 changes: 25 additions & 0 deletions test/example_app/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"presets": [
[
"env",
{
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}
],
"react"
],
"plugins": [
"syntax-dynamic-import",
[
"transform-class-properties",
{
"spec": true
}
]
]
}
4 changes: 4 additions & 0 deletions test/example_app/.postcssrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins:
postcss-smart-import: {}
precss: {}
autoprefixer: {}
7 changes: 4 additions & 3 deletions test/example_app/app/javascript/packs/application.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// This file is will automatically compiled by Webpack, along with any other files
/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript, and only use these pack files to reference
// that code, so it'll be compiled.
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
Expand Down
31 changes: 22 additions & 9 deletions test/example_app/bin/webpack
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
#!/usr/bin/env ruby
$stdout.sync = true

RAILS_ENV = ENV["RAILS_ENV"] || "development"
WEBPACK_ENV = ENV["WEBPACK_ENV"] || RAILS_ENV
require "shellwords"
require "yaml"

APP_PATH = File.expand_path("../", __dir__)
VENDOR_PATH = File.expand_path("../vendor", __dir__)
ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]

SET_NODE_PATH = "NODE_PATH=#{VENDOR_PATH}/node_modules"
WEBPACK_BIN = "./node_modules/webpack/bin/webpack.js"
WEBPACK_CONFIG = "#{APP_PATH}/config/webpack/#{WEBPACK_ENV}.js"
ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]

Dir.chdir(VENDOR_PATH) do
exec "#{SET_NODE_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG} #{ARGV.join(" ")}"
APP_PATH = File.expand_path("../", __dir__)
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")

unless File.exist?(WEBPACK_CONFIG)
puts "Webpack configuration not found."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
end
Loading

0 comments on commit 20ac97a

Please sign in to comment.