Skip to content

Commit

Permalink
Yarn migration, pt. IV: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
squadette committed Feb 16, 2017
1 parent 96b0516 commit bdf9e81
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"private": true,
"engines": {
"node": "6.9.0",
"npm": "4.1.1",
"yarn": "3.5.0"
"npm": "4.1.1"
},
"scripts": {
"postinstall": "cd client && yarn",
"postinstall": "cd client && yarn install",
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
"test": "rspec"
}
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module TestHelper
# once per test run.
#
# If you do not want to be slowed down by re-compiling webpack assets from scratch every test
# run, you can call `npm run build:client` (and `npm run build:server` if doing server
# run, you can call `yarn run build:client` (and `yarn run build:server` if doing server
# rendering) to have webpack recompile these files in the background, which will be *much*
# faster. The helper looks for these processes and will abort recompiling if it finds them
# to be running.
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/test_helper/node_process_launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def self.launch_node

path = "#{::Rails.root}/client/node"
puts "Launching NodeJS server at #{path}"
system("cd #{path} && npm start &")
system("cd #{path} && yarn start &")
sleep(1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/react_on_rails/version_checker.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ReactOnRails
# Responsible for checking versions of rubygem versus npm node package
# Responsible for checking versions of rubygem versus yarn node package
# against each otherat runtime.
class VersionChecker
attr_reader :node_package_version, :logger
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"build-watch": "babel --watch --out-dir node_package/lib node_package/src",
"eslint": "eslint .",
"flow": "flow check node_package",
"lint": "yarn run eslint && yarn run jscs && yarn run flow",
"lint": "yarn run eslint && yarn run flow",
"check": "yarn run lint && yarn run flow && yarn run test",
"prerelease": "yarn run check && yarn run clean && yarn run build",
"release:patch": "node_package/scripts/release patch",
Expand Down
5 changes: 0 additions & 5 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ namespace :lint do
sh_in_dir(gem_root, "yarn run eslint")
end

desc "Run jscs from shell"
task :jscs do
sh_in_dir(gem_root, "yarn run jscs")
end

desc "Run flow from shell"
task :flow do
sh_in_dir(gem_root, "yarn run flow")
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/Procfile.dev.no.turbolinks
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev:client'
server: sh -c 'cd client && npm run build:dev:server'
client: sh -c 'rm app/assets/webpack/* || true && cd client && yarn run build:dev:client'
server: sh -c 'cd client && yarn run build:dev:server'
web: DISABLE_TURBOLINKS=TRUE bin/rails s -b 0.0.0.0
4 changes: 2 additions & 2 deletions spec/dummy/Procfile.hot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0

# Run the hot reload server for client development
hot-assets: HOT_RAILS_PORT=3500 npm run hot-assets
hot-assets: HOT_RAILS_PORT=3500 yarn run hot-assets

# Keep the JS fresh for server rendering. Remove if not server rendering
rails-server-assets: npm run build:dev:server
rails-server-assets: yarn run build:dev:server
4 changes: 2 additions & 2 deletions spec/dummy/Procfile.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# in rails_helper.rb.

# Build client assets, watching for changes.
rails-client-assets: npm run build:dev:client
rails-client-assets: yarn run build:dev:client

# Build server assets, watching for changes. Remove if not server rendering.
rails-server-assets: npm run build:dev:server
rails-server-assets: yarn run build:dev:server
4 changes: 2 additions & 2 deletions spec/dummy/Procfile.static
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rails: REACT_ON_RAILS_ENV= rails s -b 0.0.0.0

# Build client assets, watching for changes.
rails-client-assets: sh -c 'npm run build:dev:client'
rails-client-assets: sh -c 'yarn run build:dev:client'

# Build server assets, watching for changes. Remove if not server rendering.
rails-server-assets: sh -c 'npm run build:dev:server'
rails-server-assets: sh -c 'yarn run build:dev:server'
4 changes: 2 additions & 2 deletions spec/dummy/Procfile.static.no.turbolinks
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rails: DISABLE_TURBOLINKS=TRUE REACT_ON_RAILS_ENV= rails s -b 0.0.0.0

# Build client assets, watching for changes.
rails-client-assets: sh -c 'npm run build:dev:client'
rails-client-assets: sh -c 'yarn run build:dev:client'

# Build server assets, watching for changes. Remove if not server rendering.
rails-server-assets: sh -c 'npm run build:dev:server'
rails-server-assets: sh -c 'yarn run build:dev:server'
10 changes: 5 additions & 5 deletions spec/dummy/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"postcss-loader": "^1.2.1",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-on-rails": "../../..",
"react-on-rails": "file:../../..",
"react-redux": "^5.0.1",
"react-router": "^3.0.0",
"redux": "^3.6.0",
Expand Down Expand Up @@ -63,18 +63,18 @@
"fs": false
},
"scripts": {
"lint": "npm run eslint --silent",
"lint": "yarn run eslint --silent",
"eslint": "eslint --ext .js,.jsx .",
"test": "npm run build:test && rspec",
"build:test": "npm run build:client && npm run build:server",
"test": "yarn run build:test && rspec",
"build:test": "yarn run build:client && yarn run build:server",
"build:production:client": "NODE_ENV=production webpack --config webpack.client.rails.build.config.js",
"build:production:server": "NODE_ENV=production webpack --config webpack.server.rails.build.config.js",
"build:client": "webpack --config webpack.client.rails.build.config.js",
"build:dev:client": "webpack -w --config webpack.client.rails.build.config.js",
"build:dev:server": "webpack -w --config webpack.server.rails.build.config.js",
"build:server": "webpack --config webpack.server.rails.build.config.js",
"hot-assets": "babel-node server-rails-hot.js",
"install-react-on-rails": "npm install 'react-on-rails@../../..'"
"install-react-on-rails": "yarn 'file:../../..'"
},
"author": "",
"license": "ISC"
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/client/server-rails-hot.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-var: 0, no-console: 0, import/no-extraneous-dependencies: 0 */
/* eslint-disable comma-dangle */

// This file is used by the npm script:
// This file is used by the yarn script:
// "hot-assets": "babel-node server-rails-hot.js"
//
// This is what creates the hot assets so that you can edit assets, JavaScript and Sass,
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/client/webpack.client.rails.build.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Run like this:
// cd client && npm run build:client
// cd client && yarn run build:client
// Note that Foreman (Procfile.dev) has also been configured to take care of this.

/* eslint-disable comma-dangle */
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/config/initializers/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def self.custom_context(view_context)
config.server_bundle_js_file = "server-bundle.js"

# If you are using the ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config)
# with rspec then this controls what npm command is run
# with rspec then this controls what yarn command is run
# to automatically refresh your webpack assets on every test run.
config.npm_build_test_command = "npm run build:test"
config.npm_build_test_command = "yarn run build:test"

# This configures the script to run to build the production assets by webpack. Set this to nil
# if you don't want react_on_rails building this file for you.
config.npm_build_production_command = "npm run build:production"
config.npm_build_production_command = "yarn run build:production"

################################################################################
# CLIENT RENDERING OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ namespace :assets do

desc "Compile assets with webpack"
task :webpack do
sh "cd client && npm run build:client"
sh "cd client && yarn run build:client"

# Skip next line if not doing server rendering
sh "cd client && npm run build:server"
sh "cd client && yarn run build:server"
end

task :clobber do
Expand Down
2 changes: 1 addition & 1 deletion spec/react_on_rails/generators/dev_tests_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

it "changes package.json to use local react-on-rails version of module" do
assert_file("client/package.json") do |contents|
assert_match('"react-on-rails": "../../../.."', contents)
assert_match('"react-on-rails": "file:../../../.."', contents)
refute_match('"react-on-rails": "ReactOnRails::VERSION"', contents)
end
end
Expand Down
26 changes: 20 additions & 6 deletions spec/react_on_rails/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
What to do next:
- Ensure your bundle and npm are up to date.
- Ensure your bundle and yarn installs of dependencies are up to date.
bundle && npm i
bundle && yarn
- Run the foreman command to start the rails server and run webpack in watch mode.
Expand All @@ -107,6 +107,20 @@

specify "react with redux generator contains a helpful message" do
run_generator_test_with_args(%w(--redux))
expected = <<-MSG.strip_heredoc
What to do next:
- Ensure your bundle and yarn installs of dependencies are up to date.
bundle && yarn
- Run the foreman command to start the rails server and run webpack in watch mode.
foreman start -f Procfile.dev
- Visit http://localhost:3000/hello_world and see your React On Rails app running!
MSG
expect(GeneratorMessages.output)
.to include(GeneratorMessages.format_info(expected))
end
Expand All @@ -123,7 +137,7 @@

specify "when npm is exist" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which npm").and_return("/path/to/bin")
allow(@install_generator).to receive(:`).with("which yarn").and_return("/path/to/bin")
expect(@install_generator.send(:missing_npm?)).to eq false
end
end
Expand All @@ -139,7 +153,7 @@

specify "when npm is missing" do
stub_const("RUBY_PLATFORM", "linux")
allow(@install_generator).to receive(:`).with("which npm").and_return("")
allow(@install_generator).to receive(:`).with("which yarn").and_return("")
expect(@install_generator.send(:missing_npm?)).to eq true
end
end
Expand All @@ -155,7 +169,7 @@

specify "when npm is exist" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where npm").and_return("/path/to/bin")
allow(@install_generator).to receive(:`).with("where yarn").and_return("/path/to/bin")
expect(@install_generator.send(:missing_npm?)).to eq false
end
end
Expand All @@ -171,7 +185,7 @@

specify "when npm is missing" do
stub_const("RUBY_PLATFORM", "mswin")
allow(@install_generator).to receive(:`).with("where npm").and_return("")
allow(@install_generator).to receive(:`).with("where yarn").and_return("")
expect(@install_generator.send(:missing_npm?)).to eq true
end
end
Expand Down

0 comments on commit bdf9e81

Please sign in to comment.