mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
cd34f00627
Some tests are running yarn install during the test. The directory used for isolation test is not subject to yarn workspace, and it occurs because the required package is not installed. In order to avoid this, I fixed all necessary packages to be installed before run test and use symlink to `node_modules`. This is a bit complicated, as `yarn install` needs to be run in a specific directory before running the test. However, running `yarn install` every time run the test is expensive when testing locally and should be avoided.
97 lines
2.3 KiB
Ruby
97 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rake/testtask"
|
|
|
|
task default: :test
|
|
|
|
task :package
|
|
|
|
desc "Run all unit tests"
|
|
task test: "test:isolated"
|
|
|
|
namespace :test do
|
|
task :isolated do
|
|
dash_i = [
|
|
"test",
|
|
"lib",
|
|
"../activesupport/lib",
|
|
"../actionpack/lib",
|
|
"../actionview/lib",
|
|
"../activemodel/lib"
|
|
].map { |dir| File.expand_path(dir, __dir__) }
|
|
|
|
dash_i.reverse_each do |x|
|
|
$:.unshift(x) unless $:.include?(x)
|
|
end
|
|
$-w = true
|
|
|
|
require "bundler/setup" unless defined?(Bundler)
|
|
require "active_support"
|
|
|
|
# Only generate the template app once.
|
|
require_relative "test/isolation/abstract_unit"
|
|
|
|
failing_files = []
|
|
|
|
dirs = (ENV["TEST_DIR"] || ENV["TEST_DIRS"] || "**").split(",")
|
|
test_options = ENV["TESTOPTS"].to_s.split(/[\s]+/)
|
|
|
|
test_patterns = dirs.map { |dir| "test/#{dir}/*_test.rb" }
|
|
test_files = Dir[*test_patterns].select do |file|
|
|
!file.start_with?("test/fixtures/") && !file.start_with?("test/isolation/assets/")
|
|
end.sort
|
|
|
|
if ENV["BUILDKITE_PARALLEL_JOB_COUNT"]
|
|
n = ENV["BUILDKITE_PARALLEL_JOB"].to_i
|
|
m = ENV["BUILDKITE_PARALLEL_JOB_COUNT"].to_i
|
|
|
|
test_files = test_files.each_slice(m).map { |slice| slice[n] }.compact
|
|
end
|
|
|
|
test_files.each do |file|
|
|
puts "--- #{file}"
|
|
fake_command = Shellwords.join([
|
|
FileUtils::RUBY,
|
|
"-w",
|
|
*dash_i.map { |dir| "-I#{Pathname.new(dir).relative_path_from(Pathname.pwd)}" },
|
|
file,
|
|
])
|
|
puts fake_command
|
|
|
|
# We could run these in parallel, but pretty much all of the
|
|
# railties tests already run in parallel, so ¯\_(⊙︿⊙)_/¯
|
|
Process.waitpid fork {
|
|
ARGV.clear.concat test_options
|
|
Rake.application = nil
|
|
|
|
load file
|
|
}
|
|
|
|
unless $?.success?
|
|
failing_files << file
|
|
puts "^^^ +++"
|
|
end
|
|
end
|
|
|
|
puts "--- All tests completed"
|
|
unless failing_files.empty?
|
|
puts "^^^ +++"
|
|
puts
|
|
puts "Failed in:"
|
|
failing_files.each do |file|
|
|
puts " #{file}"
|
|
end
|
|
puts
|
|
|
|
exit 1
|
|
end
|
|
end
|
|
end
|
|
|
|
Rake::TestTask.new("test:regular") do |t|
|
|
t.libs << "test" << "#{__dir__}/../activesupport/lib"
|
|
t.pattern = "test/**/*_test.rb"
|
|
t.warning = true
|
|
t.verbose = true
|
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
|
end
|