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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
# frozen_string_literal: true
require "fileutils"
require "colorator"
require "cucumber/formatter/console"
require "cucumber/formatter/io"
module Jekyll
module Cucumber
class Formatter
attr_accessor :indent, :runtime
include ::Cucumber::Formatter::Console
include ::Cucumber::Formatter::Io
include FileUtils
CHARS = {
:failed => "\u2718".red,
:pending => "\u203D".yellow,
:undefined => "\u2718".red,
:passed => "\u2714".green,
:skipped => "\u203D".blue,
}.freeze
#
def initialize(runtime, path_or_io, options)
@runtime = runtime
@snippets_input = []
@io = ensure_io(path_or_io)
@prefixes = options[:prefixes] || {}
@delayed_messages = []
@options = options
@exceptions = []
@indent = 0
@timings = {}
end
#
def before_features(_features)
print_profile_information
end
#
def after_features(features)
@io.puts
print_worst_offenders
print_summary(features)
end
#
def before_feature(_feature)
@exceptions = []
@indent = 0
end
#
def feature_element_timing_key(feature_element)
"\"#{feature_element.name}\" (#{feature_element.location})"
end
#
def before_feature_element(feature_element)
@indent = 2
@scenario_indent = 2
@timings[feature_element_timing_key(feature_element)] = Time.now
end
#
def after_feature_element(feature_element)
@timings[feature_element_timing_key(feature_element)] = Time.now - @timings[feature_element_timing_key(feature_element)]
@io.print " (#{@timings[feature_element_timing_key(feature_element)]}s)"
end
#
def tag_name(tag_name); end
def comment_line(comment_line); end
def after_tags(tags); end
#
def before_background(_background)
@scenario_indent = 2
@in_background = true
@indent = 2
end
#
def after_background(_background)
@in_background = nil
end
#
def background_name(keyword, name, source_line, indent)
print_feature_element_name(
keyword, name, source_line, indent
)
end
#
def scenario_name(keyword, name, source_line, indent)
print_feature_element_name(
keyword, name, source_line, indent
)
end
#
def before_step(step)
@current_step = step
end
#
# rubocop:disable Metrics/ParameterLists
def before_step_result(_keyword, _step_match, _multiline_arg, status, exception, \
_source_indent, background, _file_colon_line)
@hide_this_step = false
if exception
if @exceptions.include?(exception)
@hide_this_step = true
return
end
@exceptions << exception
end
if status != :failed && @in_background ^ background
@hide_this_step = true
return
end
@status = status
end
#
def step_name(_keyword, _step_match, status, _source_indent, _background, _file_colon_line)
@io.print CHARS[status]
@io.print " "
end
# rubocop:enable Metrics/ParameterLists
#
def exception(exception, status)
return if @hide_this_step
@io.puts
print_exception(exception, status, @indent)
@io.flush
end
#
def after_test_step(test_step, result)
collect_snippet_data(
test_step, result
)
end
#
def print_feature_element_name(feature_element)
@io.print "\n#{feature_element.location} Scenario: #{feature_element.name} "
@io.flush
end
#
def cell_prefix(status)
@prefixes[status]
end
#
def print_worst_offenders
@io.puts
@io.puts "Worst offenders:"
@timings.sort_by { |_f, t| -t }.take(10).each do |(f, t)|
@io.puts " #{t}s for #{f}"
end
@io.puts
end
#
def print_summary(features)
@io.puts
print_stats(features, @options)
print_snippets(@options)
print_passing_wip(@options)
end
end
end
end
AfterConfiguration do |config|
f = Jekyll::Cucumber::Formatter.new(nil, $stdout, {})
config.on_event :test_case_started do |event|
f.print_feature_element_name(event.test_case)
f.before_feature_element(event.test_case)
end
config.on_event :test_case_finished do |event|
f.after_feature_element(event.test_case)
end
config.on_event :test_run_finished do
f.print_worst_offenders
end
end
|