Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yarn issues on CI #37721

Merged
merged 4 commits into from Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions railties/test/application/assets_test.rb
Expand Up @@ -20,10 +20,7 @@ def teardown
def precompile!(env = nil)
with_env env.to_h do
quietly do
precompile_task = "bin/rails assets:precompile --trace 2>&1"
output = Dir.chdir(app_path) { %x[ #{precompile_task} ] }
assert $?.success?, output
output
rails ["assets:precompile", "--trace"]
end
end
end
Expand All @@ -37,7 +34,7 @@ def with_env(env)

def clean_assets!
quietly do
assert Dir.chdir(app_path) { system("bin/rails assets:clobber") }
rails ["assets:clobber"]
end
end

Expand Down
30 changes: 25 additions & 5 deletions railties/test/isolation/abstract_unit.rb
Expand Up @@ -502,28 +502,48 @@ class ActiveSupport::TestCase
Module.new do
extend TestHelpers::Paths

def self.sh(cmd)
output = `#{cmd}`
raise "Command #{cmd.inspect} failed. Output:\n#{output}" unless $?.success?
end

# Build a rails app
FileUtils.rm_rf(app_template_path)
FileUtils.mkdir_p(app_template_path)

`#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install`
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install --quiet"
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
f.puts "require 'rails/all'"
end

unless File.exist?("#{RAILS_FRAMEWORK_ROOT}/actionview/lib/assets/compiled/rails-ujs.js")
Dir.chdir("#{RAILS_FRAMEWORK_ROOT}/actionview") { `yarn build` }
Dir.chdir("#{RAILS_FRAMEWORK_ROOT}/actionview") do
sh "yarn build"
end
end

assets_path = "#{RAILS_FRAMEWORK_ROOT}/railties/test/isolation/assets"
unless Dir.exist?("#{assets_path}/node_modules")
Dir.chdir(assets_path) { `yarn install` }
Dir.chdir(assets_path) do
sh "yarn install"
end
end
FileUtils.cp("#{assets_path}/package.json", "#{app_template_path}/package.json")

# Fix relative file paths
package_json = File.read("#{assets_path}/package.json")
package_json.gsub!(%r{"file:(\.\./[^"]+)"}) do
path = Pathname.new($1).expand_path(assets_path).relative_path_from(Pathname.new(app_template_path))
"\"file:#{path}\""
end
File.write("#{app_template_path}/package.json", package_json)

FileUtils.cp("#{assets_path}/config/webpacker.yml", "#{app_template_path}/config/webpacker.yml")
FileUtils.cp_r("#{assets_path}/config/webpack", "#{app_template_path}/config/webpack")
FileUtils.ln_s("#{assets_path}/node_modules", "#{app_template_path}/node_modules")
FileUtils.chdir(app_template_path) { `bin/rails webpacker:binstubs` }
FileUtils.chdir(app_template_path) do
sh "yarn install"
sh "bin/rails webpacker:binstubs"
end

# Fake 'Bundler.require' -- we run using the repo's Gemfile, not an
# app-specific one: we don't want to require every gem that lists.
Expand Down