Class: Fastlane::Actions::FlutterTestsAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



38
39
40
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 38

def self.authors
  ["smaso"]
end

.available_optionsObject



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
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 51

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :flutter_command,
      default_value: 'flutter',
      description: 'Specifies the command to use flutter',
      optional: false,
      type: String
    ),
    FastlaneCore::ConfigItem.new(
      key: :print_only_failed,
      default_value: true,
      description: 'Specifies if it should only print the failed and the skipped tests',
      optional: false,
      type: Boolean
    ),
    FastlaneCore::ConfigItem.new(
      key: :print_stats,
      default_value: true,
      description: 'If defined, it will print how many tests were done/skipped/failed',
      optional: false,
      type: Boolean
    ),
    FastlaneCore::ConfigItem.new(
      key: :test_type,
      default_value: 'all',
      description: "Specifies which tests should be run. Accepted values",
      verify_block: proc do |value|
        UI.user_error!("Wrong value, #{value} not accepted. Should be 'unit','integration' or 'all'.") unless %w[unit integration all].include? value
      end,
      optional: false,
      type: String,
    ),
    FastlaneCore::ConfigItem.new(
      key: :driver_path,
      description: "Specifies the path of the driver file",
      optional: true,
      type: String,
      verify_block: proc do |value|
        UI.user_error!("Driver file doesn't exists") unless File.file?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :integration_tests,
      description: "Specifies the path of the folder containing all the integration tests",
      optional: true,
      type: String,
      verify_block: proc do |value|
        UI.user_error!("Integration test folder doesn't exists") unless File.exist?(value) && File.directory?(value)
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :platform,
      description: "Specifies the os on which the tests should run on",
      optional: false,
      type: String,
      verify_block: proc do |value|
        UI.user_error!("Platform #{value} is not supported") unless %w[android ios].include? value.to_s.downcase
      end
    ),
    FastlaneCore::ConfigItem.new(
      key: :force_launch,
      description: "If true, the plugin will try to launch an emulator in case it's not already running",
      optional: false,
      type: Boolean,
      default_value: true,
    ),
    FastlaneCore::ConfigItem.new(
      key: :reuse_build,
      description: "If true, builds the app only for the first time then the other integration tests are run on the same build (much faster)",
      default_value: false,
      optional: false,
      type: Boolean,
    )
  ]
end

.descriptionObject



34
35
36
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 34

def self.description
  "Extension that helps to run flutter tests"
end

.detailsObject



46
47
48
49
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 46

def self.details
  # Optional:
  "Extension that helps to run both unit tests and integration tests for your flutter application and parses the output given by the default tester and shows in a more readable way"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 128

def self.is_supported?(platform)
  true
end

.return_valueObject



42
43
44
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 42

def self.return_value
  "Returns 0 or 1 based on the tests output"
end

.run(params) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fastlane/plugin/flutter_tests/actions/flutter_tests_action.rb', line 11

def self.run(params)
  test_type = params[:test_type]
  if %w[all unit].include? test_type
    Helper::FlutterUnitTestHelper.new.run(params[:flutter_command], params[:print_only_failed], params[:print_stats])
  end
  if %w[all integration].include? test_type

    if params[:driver_path].nil? || params[:integration_tests].nil?
      UI.user_error!("If launching integration tests, 'driver_path' and 'integration_tests' parameters must be inserted")
      exit(1)
    end

    platform = params[:platform]

    if params[:reuse_build] && platform != 'android'
      UI.error("If 'reuse_build' is set to true, the platform must be android")
      platform = 'android'
    end

    Helper::FlutterIntegrationTestHelper.new(params[:driver_path], params[:integration_tests], params[:flutter_command]).run(platform, params[:force_launch], params[:reuse_build])
  end
end