-
Notifications
You must be signed in to change notification settings - Fork 134
/
Rakefile
101 lines (87 loc) · 2.49 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# frozen_string_literal: true
require 'rubygems'
require 'rake/testtask'
require 'bundler'
require 'bundler/gem_tasks'
require 'bundler/setup'
require 'yard'
Bundler.require(:default, :test)
YARD::Rake::YardocTask.new
BACKENDS = Dir["lib/message_bus/backends/*.rb"].map { |file| file.match(%r{backends/(?<backend>.*).rb})[:backend] } - ["base"]
SPEC_FILES = Dir['spec/**/*_spec.rb']
INTEGRATION_FILES = Dir['spec/integration/**/*_spec.rb']
module CustomBuild
def build_gem
`cp assets/message-bus* vendor/assets/javascripts`
super
end
end
module Bundler
class GemHelper
prepend CustomBuild
end
end
desc "Generate documentation for Yard, and fail if there are any warnings"
task :test_doc do
sh "yard --fail-on-warning #{'--no-progress' if ENV['CI']}"
end
namespace :jasmine do
desc "Run Jasmine tests in headless mode"
task 'ci' do
if !system("npx jasmine-browser-runner runSpecs")
exit 1
end
end
end
namespace :spec do
BACKENDS.each do |backend|
desc "Run tests on the #{backend} backend"
task backend do
begin
ENV['MESSAGE_BUS_BACKEND'] = backend
Rake::TestTask.new(backend) do |t|
t.test_files = SPEC_FILES - INTEGRATION_FILES
end
Rake::Task[backend].invoke
ensure
ENV.delete('MESSAGE_BUS_BACKEND')
end
end
end
desc "Run integration tests"
task :integration do
require "socket"
def port_available?(port)
server = TCPServer.open("0.0.0.0", port)
server.close
true
rescue Errno::EADDRINUSE
false
end
begin
ENV['MESSAGE_BUS_BACKEND'] = 'memory'
pid = spawn("bundle exec puma -p 9292 spec/fixtures/test/config.ru")
sleep 1 while port_available?(9292)
Rake::TestTask.new(:integration) do |t|
t.test_files = INTEGRATION_FILES
end
Rake::Task[:integration].invoke
ensure
ENV.delete('MESSAGE_BUS_BACKEND')
Process.kill('TERM', pid) if pid
end
end
end
desc "Run tests on all backends, plus client JS tests"
task spec: BACKENDS.map { |backend| "spec:#{backend}" } + ["jasmine:ci", "spec:integration"]
desc "Run performance benchmarks on all backends"
task :performance do
begin
ENV['MESSAGE_BUS_BACKENDS'] = BACKENDS.join(",")
sh "#{FileUtils::RUBY} -e \"ARGV.each{|f| load f}\" #{Dir['spec/performance/*.rb'].to_a.join(' ')}"
ensure
ENV.delete('MESSAGE_BUS_BACKENDS')
end
end
desc "Run all tests and confirm the documentation compiles without error"
task default: [:spec, :test_doc]