-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt Android RN test fixture to work with BitBar #1957
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
d3e8e2a
Add naive start of config file implementation
Cawllec 965ed4f
Move implementation into kotlin for simplicity
Cawllec 992ced3
Slight refactor for testing
Cawllec 039dea8
Cut pipeline right down for testing
Cawllec 9b65c44
Add missing imports and variables
Cawllec a16e8f2
Work around missing references
Cawllec a06848e
Add log import
Cawllec a0bda9b
Fix syntax error
Cawllec 10d1931
Remove invalid log
Cawllec 0d123fb
Add debug log
Cawllec 7d8b85d
Add more debugging
Cawllec d029426
Add more debugging
Cawllec acbe0fe
Use proper async await to return maze-runner address
Cawllec 509c2fb
Naive implementation of cocoa file reading
Cawllec 65a2637
More debugging
Cawllec 96e81f9
Don't pass address back up to JS
Cawllec bc1fba8
Remove superfluous function
Cawllec a754403
Remove invalid import
Cawllec fc30da3
Fix redeclaration error
Cawllec 9c3b0d3
Add general bridging header import
Cawllec 521fd6f
Add separate interface for config loader
Cawllec dc63d5e
Attempt to use seperate bridging header location
Cawllec f01e032
Remove config reading from iOS RN test fixtures due to build issues
Cawllec 3e1b604
Add feedback and extra guards against missing endpoints
Cawllec 3cdd0df
Revert changes to buildkite pipeline
Cawllec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) ?: "" | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be replaced with the file loading logic in the below swift file once it can be compiled correctly