-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt Android RN test fixture to work with BitBar (#1957)
* Add naive start of config file implementation * Move implementation into kotlin for simplicity * Slight refactor for testing * Cut pipeline right down for testing * Add missing imports and variables * Work around missing references * Add log import * Fix syntax error * Remove invalid log * Add debug log * Add more debugging * Add more debugging * Use proper async await to return maze-runner address * Naive implementation of cocoa file reading * More debugging * Don't pass address back up to JS * Remove superfluous function * Remove invalid import * Fix redeclaration error * Add general bridging header import * Add separate interface for config loader * Attempt to use seperate bridging header location * Remove config reading from iOS RN test fixtures due to build issues * Add feedback and extra guards against missing endpoints * Revert changes to buildkite pipeline
- Loading branch information
Showing
6 changed files
with
127 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,4 @@ BugsnagConfiguration *createConfiguration(NSDictionary * options); | |
|
||
@end | ||
|
||
|
||
#endif /* BugsnagModule_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
test/react-native/features/fixtures/ios-module/ConfigFileReader.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// ConfigFileReader.swift | ||
// reactnative | ||
// | ||
// Created by Alex Moinet on 04/05/2023. | ||
// Copyright © 2023 Facebook. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class FixtureConfig: Codable { | ||
var maze_address: String | ||
} | ||
|
||
class ConfigFileReader:NSObject { | ||
func loadMazeRunnerAddress() -> String { | ||
let bsAddress = "http://bs-local.com:9339" | ||
|
||
// Only iOS 12 and above will run on BitBar for now | ||
if #available(iOS 12.0, *) {} else { | ||
return bsAddress; | ||
} | ||
|
||
for _ in 1...60 { | ||
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0] | ||
|
||
NSLog("Reading Maze Runner address from fixture_config.json") | ||
do { | ||
let fileUrl = URL(fileURLWithPath: "fixture_config", | ||
relativeTo: documentsUrl).appendingPathExtension("json") | ||
let savedData = try Data(contentsOf: fileUrl) | ||
if let contents = String(data: savedData, encoding: .utf8) { | ||
let decoder = JSONDecoder() | ||
let jsonData = contents.data(using: .utf8) | ||
let config = try decoder.decode(FixtureConfig.self, from: jsonData!) | ||
let address = "http://" + config.maze_address | ||
NSLog("Using Maze Runner address: " + address) | ||
return address | ||
} | ||
} | ||
catch let error as NSError { | ||
NSLog("Failed to read fixture_config.json: \(error)") | ||
} | ||
NSLog("Waiting for fixture_config.json to appear") | ||
sleep(1) | ||
} | ||
|
||
NSLog("Unable to read from fixture_config.json, defaulting to BrowserStack environment") | ||
return bsAddress; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
test/react-native/features/fixtures/reactnative/module/ConfigFileReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.reactnative.module | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import org.json.JSONObject | ||
import java.io.File | ||
import java.io.IOException | ||
|
||
const val CONFIG_FILE_TIMEOUT = 5000 | ||
|
||
class ConfigFileReader { | ||
|
||
fun getMazeRunnerAddress(context: Context): String { | ||
val externalFilesDir = context.getExternalFilesDir(null) | ||
val configFile = File(externalFilesDir, "fixture_config.json") | ||
var mazeAddress: String? = null | ||
Log.i("Bugsnag", "Attempting to read Maze Runner address from config file ${configFile.path}") | ||
|
||
// Poll for the fixture config file | ||
val pollEnd = System.currentTimeMillis() + CONFIG_FILE_TIMEOUT | ||
while (System.currentTimeMillis() < pollEnd) { | ||
if (configFile.exists()) { | ||
val fileContents = configFile.readText() | ||
val fixtureConfig = runCatching { JSONObject(fileContents) }.getOrNull() | ||
mazeAddress = getStringSafely(fixtureConfig, "maze_address") | ||
if (!mazeAddress.isNullOrBlank()) { | ||
Log.i("Bugsnag", "Maze Runner address set from config file: $mazeAddress") | ||
break | ||
} | ||
} | ||
|
||
Thread.sleep(250) | ||
} | ||
if (mazeAddress.isNullOrBlank()) { | ||
Log.i("Bugsnag", "Failed to read Maze Runner address from config file, reverting to legacy address") | ||
mazeAddress = "bs-local.com:9339" | ||
} | ||
return mazeAddress | ||
} | ||
|
||
private fun getStringSafely(jsonObject: JSONObject?, key: String): String { | ||
return jsonObject?.optString(key) ?: "" | ||
} | ||
|
||
} |