2017-07-20 19:59:54 -05: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)
|
|
|
|
# => SKIP_CORE set to 1 to skip core rspec tests
|
|
|
|
# => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests
|
|
|
|
# => JS_ONLY set to 1 to skip all rspec tests
|
|
|
|
# => RUBY_ONLY set to 1 to skip all qunit tests
|
|
|
|
# => SINGLE_PLUGIN set to plugin name to skip eslint, and only run plugin-specific rspec tests
|
|
|
|
#
|
|
|
|
# Other useful environment variables (not specific to this rake task)
|
|
|
|
# => LOAD_PLUGINS set to 1 to load all plugins when running tests
|
|
|
|
# => MODULE set to a qunit module name to run only those tests
|
|
|
|
# => FILTER set to a qunit filter string to run only those tests
|
|
|
|
# => 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-25 01:27:09 -05:00
|
|
|
# Run all core tests:
|
2017-07-20 19:59:54 -05:00
|
|
|
# docker run discourse/discourse_test:release
|
2017-07-25 01:27:09 -05:00
|
|
|
# Run only rspec tests:
|
2017-07-20 19:59:54 -05:00
|
|
|
# docker run -e RUBY_ONLY=1 discourse/discourse_test:release
|
|
|
|
# Run all core and plugin tests (plugin mounted from host filesystem):
|
2017-07-25 01:27:09 -05:00
|
|
|
# docker run -e LOAD_PLUGINS=1 -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
|
2014-06-18 02:31:25 -05: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
|
2014-06-19 00:11:55 -05:00
|
|
|
|
2014-06-18 02:31:25 -05:00
|
|
|
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`
|
|
|
|
|
|
|
|
puts "Starting background redis"
|
|
|
|
@redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
|
|
|
|
|
2016-05-23 00:29:23 -05:00
|
|
|
@postgres_bin = "/usr/lib/postgresql/9.5/bin/"
|
2014-06-18 02:31:25 -05:00
|
|
|
`#{@postgres_bin}initdb -D tmp/test_data/pg`
|
|
|
|
|
2014-06-19 00:35:24 -05: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 02:31:25 -05:00
|
|
|
puts "Starting postgres"
|
|
|
|
@pg_pid = Process.spawn("#{@postgres_bin}postmaster -D tmp/test_data/pg")
|
|
|
|
|
|
|
|
|
|
|
|
ENV["RAILS_ENV"] = "test"
|
|
|
|
|
|
|
|
@good = run_or_fail("bundle exec rake db:create db:migrate")
|
2017-07-19 11:17:18 -05:00
|
|
|
|
|
|
|
if ENV["INSTALL_OFFICIAL_PLUGINS"]
|
|
|
|
@good &&= run_or_fail("bundle exec rake plugin:install_all_official")
|
|
|
|
end
|
|
|
|
|
2014-06-19 18:27:09 -05:00
|
|
|
unless ENV["JS_ONLY"]
|
2017-07-19 11:17:18 -05:00
|
|
|
|
|
|
|
unless ENV["SKIP_CORE"]
|
|
|
|
@good &&= run_or_fail("bundle exec rspec")
|
|
|
|
end
|
2017-03-07 02:36:49 -06:00
|
|
|
|
|
|
|
if ENV["LOAD_PLUGINS"]
|
2017-07-20 19:59:54 -05:00
|
|
|
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
|
2017-03-07 02:36:49 -06:00
|
|
|
end
|
2017-07-25 01:27:09 -05:00
|
|
|
|
2014-06-19 18:27:09 -05:00
|
|
|
end
|
2017-07-20 19:59:54 -05:00
|
|
|
|
2014-06-19 18:27:09 -05:00
|
|
|
unless ENV["RUBY_ONLY"]
|
2017-07-20 19:59:54 -05:00
|
|
|
unless ENV["SINGLE_PLUGIN"]
|
|
|
|
@good &&= run_or_fail("eslint app/assets/javascripts")
|
|
|
|
@good &&= run_or_fail("eslint --ext .es6 app/assets/javascripts")
|
|
|
|
@good &&= run_or_fail("eslint --ext .es6 test/javascripts")
|
|
|
|
@good &&= run_or_fail("eslint test/javascripts")
|
|
|
|
end
|
2017-07-25 01:27:09 -05:00
|
|
|
@good &&= run_or_fail("LOAD_PLUGINS=#{ENV["LOAD_PLUGINS"]} bundle exec rake qunit:test['600000']")
|
2014-06-19 18:27:09 -05:00
|
|
|
end
|
2014-06-18 02:31:25 -05:00
|
|
|
|
|
|
|
ensure
|
|
|
|
puts "Terminating"
|
|
|
|
|
|
|
|
Process.kill("TERM", @redis_pid)
|
|
|
|
Process.kill("TERM", @pg_pid)
|
|
|
|
Process.wait @redis_pid
|
|
|
|
Process.wait @pg_pid
|
|
|
|
end
|
|
|
|
|
|
|
|
if !@good
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|