Class: Fastlane::Actions::AnnaiRunTestsAction

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

Class Method Summary collapse

Class Method Details

.available_optionsObject


Define Parameters




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
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_run_tests_action.rb', line 58

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :platform,
                                 description: "The platform (:ios or :android)",
                                 is_string: false,
                                 verify_block: proc do |value|
                                    UI.user_error!("Platform must be :ios or :android") unless [:ios, :android].include?(value)
                                 end),
    FastlaneCore::ConfigItem.new(key: :test_spec_file,
                                 description: "Path to the annai test spec configuration file (relative to flutter root). Defaults to standard discovery",
                                 optional: true,
                                 default_value: nil),

    # --- Filtering Options (Matches IntegrationTest logic) ---
    FastlaneCore::ConfigItem.new(key: :flavor,
                                 description: "The flavor(s) to run tests against (comma-separated list, e.g., 'free,pro'). If nil, all flavors are tested",
                                 optional: true,
                                 type: String,
                                 default_value: nil),
    FastlaneCore::ConfigItem.new(key: :emulator,
                                 description: "The specific emulator/device name (as defined in the test spec) to run tests on. If nil, tests run on all defined emulators for the given flavor(s)",
                                 optional: true,
                                 type: String,
                                 default_value: nil),

    # --- Emulator Control ---
    FastlaneCore::ConfigItem.new(key: :open_emulator,
                                 description: "If true, opens the target emulator before running tests",
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :close_emulator,
                                 description: "If true, closes the target emulator after running tests",
                                 type: Boolean,
                                 default_value: true),
    FastlaneCore::ConfigItem.new(key: :wipe_data,
                                 description: "If true, wipes the emulator data before opening",
                                 type: Boolean,
                                 default_value: true),

    # --- Test Execution Control ---
    FastlaneCore::ConfigItem.new(key: :skip_screenshots,
                                 description: "If true, uses 'flutter test' instead of 'flutter drive' (skips screenshots). Overrides the spec file setting",
                                 type: Boolean,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :skip_sound_null_safety,
                                 description: "If true, adds --no-sound-null-safety flag to the flutter command",
                                 type: Boolean,
                                 default_value: false)
  ].compact
end

.descriptionObject



109
110
111
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_run_tests_action.rb', line 109

def self.description
  "Runs specified integration tests on target devices using configurations defined within the Annai test spec file"
end

.example_codeObject



117
118
119
120
121
122
123
124
125
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_run_tests_action.rb', line 117

def self.example_code
  'ann_run_tests(
    platform: :android,
    test_spec_file: "../config/my_custom_specs.yaml" # Custom path
    emulator: "Pixel_5_API_30",
    flavor: "development",
    skip_screenshots: false
  )'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_run_tests_action.rb', line 113

def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/ann_flutter_flavor/actions/ann_run_tests_action.rb', line 12

def self.run(params)
  platform = params[:platform]

  # 1. Determine the necessary paths and managers
  root_folder = FastlaneFlutterFlavor::ProjectUtil.find_flutter_root

  # Resolve the test spec file path, respecting user input precedence:
  # User Parameter > Environment Variable > Default Path
  test_spec_file_input = params[:test_spec_file]
  resolved_test_spec_path = FastlaneFlutterFlavor::ProjectUtil.find_annai_test_spec_path(test_spec_file_input)

  # Status Manager is required by IntegrationTest's constructor, though not strictly needed for open/close
  status_manager = FastlaneFlutterFlavor::StatusManager.new(lane: self)

  # 2. Instantiate IntegrationTest directly
  integration_test = FastlaneFlutterFlavor::IntegrationTest.new(
    lane: self,
    isAndroid: platform == :android,
    isIos: platform == :ios,
    test_spec_file: resolved_test_spec_path,
    statusManager: status_manager,
    root_folder: root_folder
  )

  UI.header("Running tests using IntegrationTest directly for #{platform}")

  # 3. Call the runTests method
  integration_test.runTests(
    flavor: params[:flavor],
    emulator: params[:emulator],
    open_emulator: params[:open_emulator],
    close_emulator: params[:close_emulator],
    wipe_data: params[:wipe_data],
    skip_screenshots: params[:skip_screenshots],
    skip_sound_null_safety: params[:skip_sound_null_safety]
  )

  UI.success("✅ Test execution completed for #{platform}. Check logs for results.")

  # 4. Finalize status reporting
  status_manager.displayStatus
end