2014-06-18 03:31:25 -04: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 01:11:55 -04:00
|
|
|
|
2014-06-18 03:31:25 -04: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')
|
|
|
|
|
|
|
|
@postgres_bin = "/usr/lib/postgresql/9.3/bin/"
|
|
|
|
`#{@postgres_bin}initdb -D tmp/test_data/pg`
|
|
|
|
|
2014-06-19 01:35:24 -04: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 03:31:25 -04: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")
|
2014-06-19 19:27:09 -04:00
|
|
|
unless ENV["JS_ONLY"]
|
|
|
|
@good &&= run_or_fail("bundle exec rspec")
|
|
|
|
end
|
|
|
|
unless ENV["RUBY_ONLY"]
|
2015-08-13 15:14:08 -04:00
|
|
|
@good &&= run_or_fail("eslint app/assets/javascripts")
|
2015-08-13 14:55:53 -04:00
|
|
|
@good &&= run_or_fail("eslint --ext \".es6\" app/assets/javascripts")
|
|
|
|
@good &&= run_or_fail("eslint --ext \".es6\" test/javascripts")
|
2015-08-13 15:14:08 -04:00
|
|
|
@good &&= run_or_fail("eslint test/javascripts")
|
2014-06-19 19:27:09 -04:00
|
|
|
@good &&= run_or_fail("bundle exec rake qunit:test")
|
|
|
|
end
|
2014-06-18 03:31:25 -04: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
|