2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-20 20:59:54 -04:00
|
|
|
# rake docker:test is designed to be used inside the discourse/docker_test image
|
|
|
|
# running it anywhere else will likely fail
|
|
|
|
#
|
|
|
|
# Environment Variables (specific to this rake task)
|
2017-08-22 08:47:29 -04:00
|
|
|
# => SKIP_LINT set to 1 to skip linting (eslint and rubocop)
|
|
|
|
# => SKIP_TESTS set to 1 to skip all tests
|
2022-05-25 01:00:58 -04:00
|
|
|
# => SKIP_WIZARD_TESTS set to 1 to skip wizard tests
|
2017-07-26 09:07:46 -04:00
|
|
|
# => SKIP_CORE set to 1 to skip core tests (rspec and qunit)
|
|
|
|
# => SKIP_PLUGINS set to 1 to skip plugin tests (rspec and qunit)
|
2021-05-20 21:43:47 -04:00
|
|
|
# => SKIP_INSTALL_PLUGINS comma separated list of plugins you want to skip installing
|
2017-07-20 20:59:54 -04:00
|
|
|
# => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests
|
|
|
|
# => RUBY_ONLY set to 1 to skip all qunit tests
|
2017-07-26 09:07:46 -04:00
|
|
|
# => JS_ONLY set to 1 to skip all rspec tests
|
|
|
|
# => SINGLE_PLUGIN set to plugin name to only run plugin-specific rspec tests (you'll probably want to SKIP_CORE as well)
|
|
|
|
# => BISECT set to 1 to run rspec --bisect (applies to core rspec tests only)
|
|
|
|
# => RSPEC_SEED set to seed to use for rspec tests (applies to core rspec tests only)
|
2018-04-11 02:39:39 -04:00
|
|
|
# => PAUSE_ON_TERMINATE set to 1 to pause prior to terminating redis and pg
|
2019-03-18 12:39:25 -04:00
|
|
|
# => JS_TIMEOUT set timeout for qunit tests in ms
|
2019-10-25 15:31:05 -04:00
|
|
|
# => WARMUP_TMP_FOLDER runs a single spec to warmup the tmp folder and obtain accurate results when profiling specs.
|
2017-07-20 20:59:54 -04:00
|
|
|
#
|
|
|
|
# Other useful environment variables (not specific to this rake task)
|
|
|
|
# => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
|
|
|
|
# this can also be set to a branch, e.g. "origin/tests-passed"
|
|
|
|
#
|
|
|
|
# Example usage:
|
2017-07-26 09:07:46 -04:00
|
|
|
# Run all core and plugin tests:
|
2017-07-20 20:59:54 -04:00
|
|
|
# docker run discourse/discourse_test:release
|
2017-07-25 02:27:09 -04:00
|
|
|
# Run only rspec tests:
|
2017-07-20 20:59:54 -04:00
|
|
|
# docker run -e RUBY_ONLY=1 discourse/discourse_test:release
|
2017-07-26 09:07:46 -04:00
|
|
|
# Run all plugin tests (with a plugin mounted from host filesystem):
|
|
|
|
# docker run -e SKIP_CORE=1 -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
|
|
|
|
# Run tests for a specific plugin (with a plugin mounted from host filesystem):
|
|
|
|
# docker run -e SKIP_CORE=1 SINGLE_PLUGIN='my-awesome-plugin' -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
|
|
|
|
|
2019-01-02 08:29:56 -05:00
|
|
|
def run_or_fail(command)
|
2019-05-29 06:20:33 -04:00
|
|
|
log(command)
|
2014-06-18 03:31:25 -04:00
|
|
|
pid = Process.spawn(command)
|
|
|
|
Process.wait(pid)
|
2019-01-02 08:29:56 -05:00
|
|
|
$?.exitstatus == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_or_fail_prettier(*patterns)
|
|
|
|
if patterns.any? { |p| Dir[p].any? }
|
|
|
|
patterns = patterns.map { |p| "'#{p}'" }.join(' ')
|
2022-07-07 01:29:14 -04:00
|
|
|
run_or_fail("yarn pprettier --list-different #{patterns}")
|
2019-01-02 08:29:56 -05:00
|
|
|
else
|
|
|
|
puts "Skipping prettier. Pattern not found."
|
|
|
|
true
|
|
|
|
end
|
2014-06-18 03:31:25 -04:00
|
|
|
end
|
|
|
|
|
2019-05-29 07:28:02 -04:00
|
|
|
def log(message)
|
2019-05-29 08:06:32 -04:00
|
|
|
puts "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] #{message}"
|
2019-05-29 06:20:33 -04:00
|
|
|
end
|
|
|
|
|
2014-06-18 03:31:25 -04:00
|
|
|
desc 'Run all tests (JS and code in a standalone environment)'
|
|
|
|
task 'docker:test' do
|
|
|
|
begin
|
2017-08-22 08:47:29 -04:00
|
|
|
@good = true
|
2021-06-02 14:29:47 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV['SKIP_LINT']
|
2019-01-17 14:17:44 -05:00
|
|
|
@good &&= run_or_fail("yarn install")
|
2018-06-08 05:49:31 -04:00
|
|
|
puts "Running linters/prettyfiers"
|
2018-08-30 03:55:36 -04:00
|
|
|
puts "eslint #{`yarn eslint -v`}"
|
|
|
|
puts "prettier #{`yarn prettier -v`}"
|
2018-06-20 12:34:49 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
if ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
|
2020-06-03 15:35:08 -04:00
|
|
|
@good &&= run_or_fail("bundle exec ruby script/i18n_lint.rb plugins/#{ENV["SINGLE_PLUGIN"]}/config/locales/{client,server}.en.yml")
|
2021-11-17 14:52:22 -05:00
|
|
|
@good &&= run_or_fail("yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins/#{ENV['SINGLE_PLUGIN']}")
|
2018-06-08 05:49:31 -04:00
|
|
|
|
2018-06-08 11:38:29 -04:00
|
|
|
puts "Listing prettier offenses in #{ENV['SINGLE_PLUGIN']}:"
|
2020-08-20 06:36:52 -04:00
|
|
|
@good &&= run_or_fail_prettier("plugins/#{ENV['SINGLE_PLUGIN']}/**/*.scss", "plugins/#{ENV['SINGLE_PLUGIN']}/**/*.{js,es6}")
|
2017-08-22 08:47:29 -04:00
|
|
|
else
|
2019-06-14 13:50:15 -04:00
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:update_all") unless ENV["SKIP_PLUGINS"]
|
2017-08-22 08:47:29 -04:00
|
|
|
@good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
|
2018-08-30 03:55:36 -04:00
|
|
|
@good &&= run_or_fail("yarn eslint app/assets/javascripts") unless ENV["SKIP_CORE"]
|
2021-11-17 14:52:22 -05:00
|
|
|
@good &&= run_or_fail("yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins") unless ENV["SKIP_PLUGINS"]
|
2018-06-08 05:49:31 -04:00
|
|
|
|
2020-06-03 15:35:08 -04:00
|
|
|
@good &&= run_or_fail('bundle exec ruby script/i18n_lint.rb "config/locales/{client,server}.en.yml"') unless ENV["SKIP_CORE"]
|
|
|
|
@good &&= run_or_fail('bundle exec ruby script/i18n_lint.rb "plugins/**/locales/{client,server}.en.yml"') unless ENV["SKIP_PLUGINS"]
|
|
|
|
|
2018-06-08 11:38:29 -04:00
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
puts "Listing prettier offenses in core:"
|
2022-07-07 01:29:14 -04:00
|
|
|
@good &&= run_or_fail('yarn pprettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.js"')
|
2018-06-08 11:38:29 -04:00
|
|
|
end
|
2018-06-08 05:49:31 -04:00
|
|
|
|
2018-06-08 11:38:29 -04:00
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
puts "Listing prettier offenses in plugins:"
|
2022-07-07 01:29:14 -04:00
|
|
|
@good &&= run_or_fail('yarn pprettier --list-different "plugins/**/assets/stylesheets/**/*.scss" "plugins/**/assets/javascripts/**/*.{js,es6}"')
|
2018-06-08 11:38:29 -04:00
|
|
|
end
|
2017-08-22 08:47:29 -04:00
|
|
|
end
|
|
|
|
end
|
2014-06-19 01:11:55 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV['SKIP_TESTS']
|
|
|
|
puts "Cleaning up old test tmp data in tmp/test_data"
|
|
|
|
`rm -fr tmp/test_data && mkdir -p tmp/test_data/redis && mkdir tmp/test_data/pg`
|
2014-06-18 03:31:25 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
puts "Starting background redis"
|
|
|
|
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
|
2014-06-19 01:35:24 -04:00
|
|
|
|
2022-03-21 08:21:06 -04:00
|
|
|
unless ENV['SKIP_DB_CREATE']
|
|
|
|
puts "Initializing postgres"
|
|
|
|
system("script/start_test_db.rb --skip-run", exception: true)
|
|
|
|
end
|
2022-01-17 12:45:39 -05:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
puts "Starting postgres"
|
2022-01-17 12:45:39 -05:00
|
|
|
@pg_pid = Process.spawn("script/start_test_db.rb --skip-setup --exec")
|
2017-07-19 12:17:18 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
2019-03-20 21:50:16 -04:00
|
|
|
# this shaves all the creation of the multisite db off
|
|
|
|
# for js tests
|
|
|
|
ENV["SKIP_MULTISITE"] = "1" if ENV["JS_ONLY"]
|
2017-07-19 12:17:18 -04:00
|
|
|
|
2022-03-21 08:21:06 -04:00
|
|
|
unless ENV['SKIP_DB_CREATE']
|
|
|
|
@good &&= run_or_fail("bundle exec rake db:create")
|
|
|
|
end
|
2019-06-26 11:54:39 -04:00
|
|
|
|
2019-07-08 14:27:51 -04:00
|
|
|
if ENV['USE_TURBO']
|
|
|
|
@good &&= run_or_fail("bundle exec rake parallel:create")
|
|
|
|
end
|
2018-06-07 04:15:12 -04:00
|
|
|
|
2018-10-22 17:30:33 -04:00
|
|
|
if ENV["INSTALL_OFFICIAL_PLUGINS"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:install_all_official")
|
|
|
|
end
|
|
|
|
|
2019-06-13 09:58:57 -04:00
|
|
|
if ENV["UPDATE_ALL_PLUGINS"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:update_all")
|
|
|
|
end
|
|
|
|
|
2020-06-05 11:59:23 -04:00
|
|
|
if skip_install = ENV["SKIP_INSTALL_PLUGINS"]
|
|
|
|
skip_install.split(",").map(&:strip).each do |plugin|
|
|
|
|
puts "[SKIP_INSTALL_PLUGINS] Removing #{plugin}"
|
|
|
|
`rm -fr plugins/#{plugin}`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-26 11:54:39 -04:00
|
|
|
command_prefix =
|
|
|
|
if ENV["SKIP_PLUGINS"]
|
2019-12-10 11:03:23 -05:00
|
|
|
# Make sure not to load plugins. bin/rake will add LOAD_PLUGINS=1 automatically unless we set it to 0 explicitly
|
|
|
|
"LOAD_PLUGINS=0 "
|
2019-06-26 11:54:39 -04:00
|
|
|
else
|
|
|
|
"LOAD_PLUGINS=1 "
|
|
|
|
end
|
|
|
|
|
2019-07-08 14:27:51 -04:00
|
|
|
@good &&= run_or_fail("#{command_prefix}bundle exec rake db:migrate")
|
|
|
|
|
|
|
|
if ENV['USE_TURBO']
|
2019-12-10 11:03:23 -05:00
|
|
|
@good &&= run_or_fail("#{command_prefix}bundle exec rake parallel:migrate")
|
2019-07-08 14:27:51 -04:00
|
|
|
end
|
2018-06-07 03:20:06 -04:00
|
|
|
|
2018-09-12 11:43:21 -04:00
|
|
|
unless ENV["JS_ONLY"]
|
2019-10-25 15:31:05 -04:00
|
|
|
if ENV['WARMUP_TMP_FOLDER']
|
2019-11-13 16:34:10 -05:00
|
|
|
run_or_fail('bundle exec rspec ./spec/requests/groups_controller_spec.rb')
|
2019-10-25 15:31:05 -04:00
|
|
|
end
|
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
params = []
|
2019-06-26 12:04:29 -04:00
|
|
|
|
|
|
|
unless ENV['USE_TURBO']
|
|
|
|
params << "--profile"
|
|
|
|
params << "--fail-fast"
|
|
|
|
if ENV["BISECT"]
|
|
|
|
params << "--bisect"
|
|
|
|
end
|
|
|
|
if ENV["RSPEC_SEED"]
|
|
|
|
params << "--seed #{ENV["RSPEC_SEED"]}"
|
|
|
|
end
|
2017-08-22 08:47:29 -04:00
|
|
|
end
|
2019-02-28 16:36:22 -05:00
|
|
|
|
|
|
|
if ENV['PARALLEL']
|
|
|
|
parts = ENV['PARALLEL'].split("/")
|
|
|
|
total = parts[1].to_i
|
|
|
|
subset = parts[0].to_i - 1
|
|
|
|
|
|
|
|
spec_partials = Dir["spec/**/*_spec.rb"].sort.in_groups(total, false)
|
2019-03-19 09:23:10 -04:00
|
|
|
# quick and dirty load balancing
|
2019-03-19 09:59:03 -04:00
|
|
|
if (spec_partials.count > 3)
|
2019-05-01 22:47:18 -04:00
|
|
|
spec_partials[0].concat(spec_partials[total - 1].shift(30))
|
|
|
|
spec_partials[1].concat(spec_partials[total - 2].shift(30))
|
2019-03-19 09:23:10 -04:00
|
|
|
end
|
|
|
|
|
2019-02-28 16:36:22 -05:00
|
|
|
params << spec_partials[subset].join(' ')
|
|
|
|
|
|
|
|
puts "Running spec subset #{subset + 1} of #{total}"
|
|
|
|
end
|
|
|
|
|
2019-06-26 11:54:39 -04:00
|
|
|
if ENV['USE_TURBO']
|
2020-08-07 12:04:55 -04:00
|
|
|
@good &&= run_or_fail("bundle exec ./bin/turbo_rspec --verbose #{params.join(' ')}".strip)
|
2019-06-26 11:54:39 -04:00
|
|
|
else
|
|
|
|
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
|
|
|
end
|
2017-07-20 20:59:54 -04:00
|
|
|
end
|
2017-07-25 02:27:09 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
if ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
|
|
|
else
|
2019-11-22 13:27:47 -05:00
|
|
|
fail_fast = "RSPEC_FAILFAST=1" unless ENV["SKIP_FAILFAST"]
|
|
|
|
@good &&= run_or_fail("#{fail_fast} bundle exec rake plugin:spec")
|
2017-08-22 08:47:29 -04:00
|
|
|
end
|
|
|
|
end
|
2017-07-26 09:07:46 -04:00
|
|
|
end
|
2017-07-27 11:29:18 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV["RUBY_ONLY"]
|
2019-03-18 12:39:25 -04:00
|
|
|
js_timeout = ENV["JS_TIMEOUT"].presence || 900_000 # 15 minutes
|
2022-03-14 13:53:21 -04:00
|
|
|
@good &&= run_or_fail 'yarn install'
|
2019-03-18 12:39:25 -04:00
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
unless ENV["SKIP_CORE"]
|
2022-03-14 13:32:03 -04:00
|
|
|
@good &&= run_or_fail("cd app/assets/javascripts/discourse && CI=1 yarn ember exam --random")
|
2017-08-22 08:47:29 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
if ENV["SINGLE_PLUGIN"]
|
2022-06-20 10:33:05 -04:00
|
|
|
@good &&= run_or_fail("CI=1 bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','#{js_timeout}']")
|
2017-08-22 08:47:29 -04:00
|
|
|
else
|
2022-06-20 10:33:05 -04:00
|
|
|
@good &&= run_or_fail("CI=1 bundle exec rake plugin:qunit['*','#{js_timeout}']")
|
2021-04-29 13:51:34 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-22 08:47:29 -04:00
|
|
|
end
|
2014-06-19 19:27:09 -04:00
|
|
|
end
|
2014-06-18 03:31:25 -04:00
|
|
|
ensure
|
|
|
|
puts "Terminating"
|
|
|
|
|
2018-04-11 02:39:39 -04:00
|
|
|
if ENV['PAUSE_ON_TERMINATE']
|
|
|
|
puts "Pausing prior to termination"
|
2018-04-11 02:46:27 -04:00
|
|
|
sleep
|
2018-04-11 02:39:39 -04:00
|
|
|
end
|
|
|
|
|
2017-08-22 08:47:29 -04:00
|
|
|
Process.kill("TERM", @redis_pid) if @redis_pid
|
|
|
|
Process.kill("TERM", @pg_pid) if @pg_pid
|
|
|
|
Process.wait @redis_pid if @redis_pid
|
|
|
|
Process.wait @pg_pid if @pg_pid
|
2014-06-18 03:31:25 -04:00
|
|
|
end
|
|
|
|
|
2021-06-02 14:29:47 -04:00
|
|
|
exit 1 unless @good
|
2014-06-18 03:31:25 -04:00
|
|
|
end
|