semaphore_test_boosters 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/test_boosters/cli_parser.rb +3 -1
- data/lib/test_boosters/cucumber_booster.rb +71 -0
- data/lib/test_boosters/display_files.rb +3 -1
- data/lib/test_boosters/executor.rb +3 -1
- data/lib/test_boosters/leftover_files.rb +29 -0
- data/lib/test_boosters/logger.rb +3 -1
- data/lib/test_boosters/rspec_booster.rb +11 -11
- data/lib/test_boosters/version.rb +1 -1
- data/lib/test_boosters.rb +1 -0
- data/script/cucumber_booster +8 -0
- data/test_data/a.feature +1 -0
- data/test_data/b.feature +1 -0
- data/test_data/c.feature +1 -0
- metadata +7 -2
- data/lib/test_boosters/leftover_specs.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19d8e45b1a80f42a4c02d663029c796a6f96151b
|
4
|
+
data.tar.gz: c3a59300fe1bca57b29528310ae48968a11c1fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f84e35496c067188e94c7d2c0f070dee0f4077db3c24264ef924c2b20cae5ef6fa1abbba92bd1c24e1c0267392ef3b456a0d8f054f345be1f3366a5d2089436
|
7
|
+
data.tar.gz: a2e2bf774eb857ba5d0bbf7d055427e240380dc5467012d5aa0d6e0e03338d8f49a531c026e1901e3c8697ca3c42ad1301cfb9c44186e79e3438465e29b50921
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Semaphore
|
2
|
+
require "json"
|
3
|
+
require "test_boosters/cli_parser"
|
4
|
+
require "test_boosters/logger"
|
5
|
+
require "test_boosters/executor"
|
6
|
+
require "test_boosters/display_files"
|
7
|
+
require "test_boosters/leftover_files"
|
8
|
+
|
9
|
+
class CucumberBooster
|
10
|
+
def initialize(thread_index)
|
11
|
+
@thread_index = thread_index
|
12
|
+
@report_path = ENV["REPORT_PATH"] || "#{ENV["HOME"]}/cucumber_report.json"
|
13
|
+
@spec_path = ENV["SPEC_PATH"] || "features"
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
begin
|
18
|
+
features_to_run = select
|
19
|
+
|
20
|
+
if features_to_run.empty?
|
21
|
+
puts "No feature files in this thread!"
|
22
|
+
else
|
23
|
+
Semaphore::execute("bundle exec cucumber #{features_to_run.join(" ")}")
|
24
|
+
end
|
25
|
+
rescue StandardError => e
|
26
|
+
if @thread_index == 0
|
27
|
+
Semaphore::execute("bundle exec cucumber #{@spec_path}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def select
|
33
|
+
with_fallback do
|
34
|
+
feature_report = JSON.parse(File.read(@report_path))
|
35
|
+
thread_count = feature_report.count
|
36
|
+
thread = feature_report[@thread_index]
|
37
|
+
|
38
|
+
all_features = Dir["#{@spec_path}/**/*.feature"].sort
|
39
|
+
all_known_features = feature_report.map { |t| t["files"] }.flatten.sort
|
40
|
+
|
41
|
+
all_leftover_features = all_features - all_known_features
|
42
|
+
thread_leftover_features = LeftoverFiles::select(all_leftover_features, thread_count, @thread_index)
|
43
|
+
thread_features = all_features & thread["files"].sort
|
44
|
+
features_to_run = thread_features + thread_leftover_features
|
45
|
+
|
46
|
+
Semaphore::display_files("This thread specs:", thread_features)
|
47
|
+
Semaphore::display_files("This thread leftover specs:", thread_leftover_features)
|
48
|
+
Semaphore::display_files("All leftover specs:", all_leftover_features)
|
49
|
+
|
50
|
+
features_to_run
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def with_fallback
|
55
|
+
yield
|
56
|
+
rescue StandardError => e
|
57
|
+
error = %{
|
58
|
+
WARNING: An error detected while parsing the test boosters report file.
|
59
|
+
WARNING: All tests will be executed on the first thread.
|
60
|
+
}
|
61
|
+
|
62
|
+
puts error
|
63
|
+
|
64
|
+
error += %{Exception: #{e.message}}
|
65
|
+
|
66
|
+
Semaphore::log(error)
|
67
|
+
|
68
|
+
raise
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module LeftoverFiles
|
2
|
+
module_function
|
3
|
+
|
4
|
+
def self.select(all_leftover_files, thread_count, thread_index)
|
5
|
+
all_leftover_files = sort_by_size(all_leftover_files)
|
6
|
+
|
7
|
+
return [] if all_leftover_files.empty?
|
8
|
+
|
9
|
+
files = all_leftover_files
|
10
|
+
.each_slice(thread_count)
|
11
|
+
.reduce{ |acc, slice| acc.map{|a| a}.zip(slice.reverse) }
|
12
|
+
.map{ |f| f.kind_of?(Array) ? f.flatten : [f] } [thread_index]
|
13
|
+
|
14
|
+
if files.nil? then []
|
15
|
+
elsif files.kind_of?(Array) then files.compact
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.sort_by_size(files) # descending
|
20
|
+
files
|
21
|
+
.select { |f| File.file?(f) }
|
22
|
+
.map{ |f| [f, File.size(f)] }
|
23
|
+
.sort_by{ |a| a[1] }
|
24
|
+
.map{ |a| a[0] }
|
25
|
+
.reverse
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
data/lib/test_boosters/logger.rb
CHANGED
@@ -4,11 +4,9 @@ module Semaphore
|
|
4
4
|
require "test_boosters/logger"
|
5
5
|
require "test_boosters/executor"
|
6
6
|
require "test_boosters/display_files"
|
7
|
-
require "test_boosters/
|
7
|
+
require "test_boosters/leftover_files"
|
8
8
|
|
9
9
|
class RspecBooster
|
10
|
-
Error = -1
|
11
|
-
|
12
10
|
def initialize(thread_index)
|
13
11
|
@thread_index = thread_index
|
14
12
|
@report_path = ENV["REPORT_PATH"] || "#{ENV["HOME"]}/rspec_report.json"
|
@@ -16,16 +14,18 @@ module Semaphore
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def run
|
19
|
-
|
17
|
+
begin
|
18
|
+
specs_to_run = select
|
20
19
|
|
21
|
-
|
20
|
+
if specs_to_run.empty?
|
21
|
+
puts "No spec files in this thread!"
|
22
|
+
else
|
23
|
+
Semaphore::execute("bundle exec rspec #{specs_to_run.join(" ")}")
|
24
|
+
end
|
25
|
+
rescue StandardError => e
|
22
26
|
if @thread_index == 0
|
23
27
|
Semaphore::execute("bundle exec rspec #{@spec_path}")
|
24
28
|
end
|
25
|
-
elsif specs_to_run.empty?
|
26
|
-
puts "No spec files in this thread!"
|
27
|
-
else
|
28
|
-
Semaphore::execute("bundle exec rspec #{specs_to_run.join(" ")}")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -39,7 +39,7 @@ module Semaphore
|
|
39
39
|
all_known_specs = rspec_report.map { |t| t["files"] }.flatten.sort
|
40
40
|
|
41
41
|
all_leftover_specs = all_specs - all_known_specs
|
42
|
-
thread_leftover_specs =
|
42
|
+
thread_leftover_specs = LeftoverFiles::select(all_leftover_specs, thread_count, @thread_index)
|
43
43
|
thread_specs = all_specs & thread["files"].sort
|
44
44
|
specs_to_run = thread_specs + thread_leftover_specs
|
45
45
|
|
@@ -66,7 +66,7 @@ module Semaphore
|
|
66
66
|
|
67
67
|
Semaphore::log(error)
|
68
68
|
|
69
|
-
|
69
|
+
raise
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
data/lib/test_boosters.rb
CHANGED
data/test_data/a.feature
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
12345678901234567890
|
data/test_data/b.feature
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
123
|
data/test_data/c.feature
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
123456789
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semaphore_test_boosters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MAINTAINER Rendered Text
|
@@ -70,16 +70,21 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- lib/test_boosters.rb
|
72
72
|
- lib/test_boosters/cli_parser.rb
|
73
|
+
- lib/test_boosters/cucumber_booster.rb
|
73
74
|
- lib/test_boosters/display_files.rb
|
74
75
|
- lib/test_boosters/executor.rb
|
75
|
-
- lib/test_boosters/
|
76
|
+
- lib/test_boosters/leftover_files.rb
|
76
77
|
- lib/test_boosters/logger.rb
|
77
78
|
- lib/test_boosters/rspec_booster.rb
|
78
79
|
- lib/test_boosters/version.rb
|
80
|
+
- script/cucumber_booster
|
79
81
|
- script/rspec_booster
|
80
82
|
- test_boosters.gemspec
|
83
|
+
- test_data/a.feature
|
81
84
|
- test_data/a_spec.rb
|
85
|
+
- test_data/b.feature
|
82
86
|
- test_data/b_spec.rb
|
87
|
+
- test_data/c.feature
|
83
88
|
- test_data/c_spec.rb
|
84
89
|
homepage: https://github.com/renderedtext/test-boosters
|
85
90
|
licenses:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module LeftoverSpecs
|
2
|
-
def self.select(all_leftover_specs, thread_count, thread_index)
|
3
|
-
all_leftover_specs = sort_by_size(all_leftover_specs)
|
4
|
-
|
5
|
-
return [] if all_leftover_specs.empty?
|
6
|
-
|
7
|
-
specs = all_leftover_specs
|
8
|
-
.each_slice(thread_count)
|
9
|
-
.reduce{|acc, slice| acc.map{|a| a}.zip(slice.reverse)}
|
10
|
-
.map{|f| if f.kind_of?(Array) then f.flatten else [f] end} [thread_index]
|
11
|
-
|
12
|
-
if specs.nil? then []
|
13
|
-
elsif specs.kind_of?(Array) then specs.compact
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.sort_by_size(specs) # descending
|
18
|
-
specs
|
19
|
-
.map{|f| if File.file?(f) then f else nil end}
|
20
|
-
.compact
|
21
|
-
.map{|f| [f, File.size(f)]}
|
22
|
-
.sort_by{|a| a[1]}.map{|a| a[0]}.reverse
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
end
|