2017-07-21 08:59:54 +08: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 20:47:29 +08:00
|
|
|
# => SKIP_LINT set to 1 to skip linting (eslint and rubocop)
|
|
|
|
# => SKIP_TESTS set to 1 to skip all tests
|
2017-07-26 21:07:46 +08: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)
|
2017-07-21 08:59:54 +08: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 21:07:46 +08: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 14:39:39 +08:00
|
|
|
# => PAUSE_ON_TERMINATE set to 1 to pause prior to terminating redis and pg
|
2017-07-21 08:59:54 +08: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-28 09:20:09 +08:00
|
|
|
# Run all core and plugin tests:
|
2017-07-21 08:59:54 +08:00
|
|
|
# docker run discourse/discourse_test:release
|
2017-07-25 14:27:09 +08:00
|
|
|
# Run only rspec tests:
|
2017-07-21 08:59:54 +08:00
|
|
|
# docker run -e RUBY_ONLY=1 discourse/discourse_test:release
|
2017-07-26 21:07:46 +08: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
|
|
|
|
|
2014-06-18 15:31:25 +08:00
|
|
|
def run_or_fail(command)
|
|
|
|
pid = Process.spawn(command)
|
|
|
|
Process.wait(pid)
|
|
|
|
$?.exitstatus == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Run all tests (JS and code in a standalone environment)'
|
|
|
|
task 'docker:test' do
|
|
|
|
begin
|
2017-08-22 20:47:29 +08:00
|
|
|
@good = true
|
|
|
|
unless ENV['SKIP_LINT']
|
2018-06-08 17:49:31 +08:00
|
|
|
puts "Running linters/prettyfiers"
|
2018-06-21 00:34:49 +08:00
|
|
|
puts "eslint #{`eslint -v`}"
|
|
|
|
puts "prettier #{`prettier -v`}"
|
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
if ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
|
|
|
|
@good &&= run_or_fail("eslint --ext .es6 plugins/#{ENV['SINGLE_PLUGIN']}")
|
2018-06-08 17:49:31 +08:00
|
|
|
|
2018-06-08 23:38:29 +08:00
|
|
|
puts "Listing prettier offenses in #{ENV['SINGLE_PLUGIN']}:"
|
2018-06-21 00:26:43 +08:00
|
|
|
@good &&= run_or_fail("prettier --list-different 'plugins/#{ENV['SINGLE_PLUGIN']}/**/*.scss' 'plugins/#{ENV['SINGLE_PLUGIN']}/**/*.es6'")
|
2017-08-22 20:47:29 +08:00
|
|
|
else
|
|
|
|
@good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
|
|
|
|
@good &&= run_or_fail("eslint app/assets/javascripts test/javascripts") unless ENV["SKIP_CORE"]
|
|
|
|
@good &&= run_or_fail("eslint --ext .es6 app/assets/javascripts test/javascripts plugins") unless ENV["SKIP_PLUGINS"]
|
2018-06-08 17:49:31 +08:00
|
|
|
|
2018-06-08 23:38:29 +08:00
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
puts "Listing prettier offenses in core:"
|
2018-06-21 00:26:43 +08:00
|
|
|
@good &&= run_or_fail('prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.es6" "test/javascripts/**/*.es6"')
|
2018-06-08 23:38:29 +08:00
|
|
|
end
|
2018-06-08 17:49:31 +08:00
|
|
|
|
2018-06-08 23:38:29 +08:00
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
puts "Listing prettier offenses in plugins:"
|
2018-06-21 00:26:43 +08:00
|
|
|
@good &&= run_or_fail('prettier --list-different "plugins/**/*.scss" "plugins/**/*.es6"')
|
2018-06-08 23:38:29 +08:00
|
|
|
end
|
2017-08-22 20:47:29 +08:00
|
|
|
end
|
|
|
|
end
|
2014-06-19 13:11:55 +08:00
|
|
|
|
2017-08-22 20:47:29 +08: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 15:31:25 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
puts "Starting background redis"
|
|
|
|
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
|
2014-06-19 13:35:24 +08:00
|
|
|
|
2018-04-04 10:28:23 +08:00
|
|
|
@postgres_bin = "/usr/lib/postgresql/10/bin/"
|
2017-08-22 20:47:29 +08:00
|
|
|
`#{@postgres_bin}initdb -D tmp/test_data/pg`
|
2014-06-18 15:31:25 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
# speed up db, never do this in production mmmmk
|
|
|
|
`echo fsync = off >> tmp/test_data/pg/postgresql.conf`
|
|
|
|
`echo full_page_writes = off >> tmp/test_data/pg/postgresql.conf`
|
|
|
|
`echo shared_buffers = 500MB >> tmp/test_data/pg/postgresql.conf`
|
2014-06-18 15:31:25 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
puts "Starting postgres"
|
|
|
|
@pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
|
2017-07-20 00:17:18 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
ENV["RAILS_ENV"] = "test"
|
2017-07-20 00:17:18 +08:00
|
|
|
|
2018-06-07 16:15:12 +08:00
|
|
|
@good &&= run_or_fail("bundle exec rake db:create")
|
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
if ENV["INSTALL_OFFICIAL_PLUGINS"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:install_all_official")
|
2017-07-20 00:17:18 +08:00
|
|
|
end
|
2017-03-07 16:36:49 +08:00
|
|
|
|
2018-06-07 16:15:12 +08:00
|
|
|
@good &&= run_or_fail("bundle exec rake db:migrate")
|
2018-06-07 15:20:06 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
unless ENV["JS_ONLY"]
|
|
|
|
|
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
params = []
|
|
|
|
if ENV["BISECT"]
|
|
|
|
params << "--bisect"
|
|
|
|
end
|
|
|
|
if ENV["RSPEC_SEED"]
|
|
|
|
params << "--seed #{ENV["RSPEC_SEED"]}"
|
|
|
|
end
|
|
|
|
@good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
|
2017-07-21 08:59:54 +08:00
|
|
|
end
|
2017-07-25 14:27:09 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
if ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
|
|
|
|
else
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:spec")
|
|
|
|
end
|
|
|
|
end
|
2017-07-21 08:59:54 +08:00
|
|
|
|
2017-07-26 21:07:46 +08:00
|
|
|
end
|
2017-07-27 23:29:18 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
unless ENV["RUBY_ONLY"]
|
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake qunit:test['600000']")
|
|
|
|
@good &&= run_or_fail("bundle exec rake qunit:test['600000','/wizard/qunit']")
|
|
|
|
end
|
|
|
|
|
|
|
|
unless ENV["SKIP_PLUGINS"]
|
|
|
|
if ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','600000']")
|
|
|
|
else
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:qunit['*','600000']")
|
|
|
|
end
|
2017-07-26 21:07:46 +08:00
|
|
|
end
|
2017-07-27 23:29:18 +08:00
|
|
|
|
2017-08-22 20:47:29 +08:00
|
|
|
end
|
2014-06-20 07:27:09 +08:00
|
|
|
end
|
2014-06-18 15:31:25 +08:00
|
|
|
|
|
|
|
ensure
|
|
|
|
puts "Terminating"
|
|
|
|
|
2018-04-11 14:39:39 +08:00
|
|
|
if ENV['PAUSE_ON_TERMINATE']
|
|
|
|
puts "Pausing prior to termination"
|
2018-04-11 14:46:27 +08:00
|
|
|
sleep
|
2018-04-11 14:39:39 +08:00
|
|
|
end
|
|
|
|
|
2017-08-22 20:47:29 +08: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 15:31:25 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if !@good
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|