Class: Fastlane::Helper::FlutterUnitTestHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::FlutterUnitTestHelper
- Defined in:
- lib/fastlane/plugin/flutter_tests/helper/flutter_unit_test_helper.rb
Instance Method Summary collapse
-
#initialize ⇒ FlutterUnitTestHelper
constructor
A new instance of FlutterUnitTestHelper.
-
#parse_json_output(line, print_only_failed) ⇒ Object
Parses the json output given by [self.run].
-
#run(flutter_command, print_only_failed, print_stats) ⇒ Object
Launches all the unit tests contained in the project folder.
Constructor Details
#initialize ⇒ FlutterUnitTestHelper
Returns a new instance of FlutterUnitTestHelper.
8 9 10 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_unit_test_helper.rb', line 8 def initialize @launched_tests = Hash.new { |hash, key| hash[key] = nil } end |
Instance Method Details
#parse_json_output(line, print_only_failed) ⇒ Object
Parses the json output given by [self.run]
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 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_unit_test_helper.rb', line 65 def parse_json_output(line, print_only_failed) unless line.to_s.strip.empty? output = JSON.parse(line) unless output.kind_of?(Array) type = output['type'] case type when 'testStart' id = output['test']['id'] name = output['test']['name'] if name.include?('loading') return end test_item = Test.new(id, name) @launched_tests[test_item.get_id] = test_item when 'testDone' test_id = output['testID'] test_item = @launched_tests[test_id] if !test_item.nil? && test_item.can_print was_skipped = output['skipped'] test_item.mark_as_done(output['result'], was_skipped, nil, nil) if was_skipped || !print_only_failed UI.(test_item.) end end when 'error' test_id = output['testID'] test_item = @launched_tests[test_id] if !test_item.nil? && test_item.can_print test_item.mark_as_done('error', false, output['error'], output['stackTrace']) UI.(test_item.) end else # ignored end end end rescue StandardError => e UI.error("Got error during parse_json: #{e.}") UI.error(e.backtrace.join('\n')) exit(1) end |
#run(flutter_command, print_only_failed, print_stats) ⇒ Object
Launches all the unit tests contained in the project folder
the launched tests
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 |
# File 'lib/fastlane/plugin/flutter_tests/helper/flutter_unit_test_helper.rb', line 19 def run(flutter_command, print_only_failed, print_stats) Open3.popen3("#{flutter_command} test --machine") do |stdin, stdout, stderr, thread| stdout.each_line do |line| parse_json_output(line, print_only_failed) end end if print_stats stats = Hash.new { |hash, key| hash[key] = 0 } @launched_tests.values.each do |item| unless item.nil? stats[item.get_status] += 1 end end skipped_tests = stats['skipped'].nil? ? 0 : stats['skipped'] failed_tests = stats['error'].nil? ? 0 : stats['error'] successful_tests = stats['success'].nil? ? 0 : stats['success'] table = [ %w[Successful Failed Skipped], [successful_tests, failed_tests, skipped_tests] ] = ["Ran #{@launched_tests.values.count { |e| !e.nil? }} tests"] colors = { 0 => 'green', 1 => 'red', 2 => 'blue' } max_length = 0 (0..2).each do |i| msg = "#{table[0][i]}:\t#{table[1][i]}" max_length = [max_length, msg.length].max .append(Utilities.new.colorize(msg, colors[i])) end UI.('-' * max_length) .each { |m| UI.(m) } UI.('-' * max_length) unless failed_tests == 0 UI.user_error!("There are some unitTests that fail") end end end |