-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert react-native-navigation scenarios
- Loading branch information
1 parent
ead3991
commit 7db5a2d
Showing
8 changed files
with
253 additions
and
167 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
38 changes: 38 additions & 0 deletions
38
test/react-native/features/fixtures/app/react_native_navigation_js/lib/CommandRunner.js
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,38 @@ | ||
import { getMazeRunnerAddress } from './ConfigFileReader' | ||
|
||
const INTERVAL = 500 | ||
|
||
let mazeAddress | ||
|
||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
export async function getCurrentCommand () { | ||
if (!mazeAddress) { | ||
mazeAddress = await getMazeRunnerAddress() | ||
} | ||
|
||
const url = `http://${mazeAddress}/command` | ||
console.error(`[Bugsnag CommandRunner] Fetching command from ${url}`) | ||
|
||
while (true) { | ||
try { | ||
// eslint-disable-next-line no-undef | ||
const response = await fetch(url) | ||
const text = await response.text() | ||
console.error(`[Bugsnag CommandRunner] Response from maze runner: ${text}`) | ||
|
||
const command = JSON.parse(text) | ||
|
||
// keep polling until a scenario command is received | ||
if (command.action !== 'noop') { | ||
console.error(`[Bugsnag CommandRunner] Received command from maze runner: ${JSON.stringify(command)}`) | ||
|
||
return command | ||
} | ||
} catch (err) { | ||
console.error(`[Bugsnag CommandRunner] Error fetching command from maze runner: ${err.message}`, err) | ||
} | ||
|
||
await delay(INTERVAL) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
test/react-native/features/fixtures/app/react_native_navigation_js/lib/ConfigFileReader.js
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,32 @@ | ||
import { Platform } from 'react-native' | ||
import { Dirs, FileSystem } from 'react-native-file-access' | ||
|
||
const TIMEOUT = 60000 | ||
|
||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
const getMazeRunnerAddress = async () => { | ||
let configFilePath | ||
const startTime = Date.now() | ||
|
||
// poll for the config file to exist | ||
while (Date.now() - startTime < TIMEOUT) { | ||
const configFileDir = Platform.OS === 'android' ? '/data/local/tmp' : Dirs.DocumentDir | ||
configFilePath = `${configFileDir}/fixture_config.json` | ||
const configFileExists = await FileSystem.exists(configFilePath) | ||
|
||
if (configFileExists) { | ||
const configFile = await FileSystem.readFile(configFilePath) | ||
console.error(`[Bugsnag ConfigFileReader] found config file at '${configFilePath}'. contents: ${configFile}`) | ||
const config = JSON.parse(configFile) | ||
return `${config.maze_address}` | ||
} | ||
|
||
await delay(500) | ||
} | ||
|
||
console.error(`[Bugsnag ConfigFileReader] no config file found at ${configFilePath}, falling back to 'localhost:9339'`) | ||
return 'localhost:9339' | ||
} | ||
|
||
module.exports.getMazeRunnerAddress = getMazeRunnerAddress |
101 changes: 101 additions & 0 deletions
101
test/react-native/features/fixtures/app/react_native_navigation_js/lib/ScenarioLauncher.js
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,101 @@ | ||
import * as Scenarios from '../Scenarios' | ||
import { getCurrentCommand } from './CommandRunner' | ||
import { NativeModules } from 'react-native' | ||
import Bugsnag from '@bugsnag/react-native' | ||
|
||
async function runScenario (scenarioName, apiKey, notifyEndpoint, sessionEndpoint, scenarioData, setScenario) { | ||
console.error(`[Bugsnag ScenarioLauncher] running scenario: ${scenarioName}`) | ||
|
||
const nativeConfig = { | ||
apiKey, | ||
autoTrackSessions: false, | ||
endpoints: { | ||
notify: notifyEndpoint, | ||
sessions: sessionEndpoint | ||
} | ||
} | ||
|
||
const jsConfig = {} | ||
|
||
// create the scenario and allow it to modify the configuration | ||
const scenario = new Scenarios[scenarioName](nativeConfig, jsConfig, scenarioData) | ||
|
||
console.error(`[Bugsnag ScenarioLauncher] with config: ${JSON.stringify(nativeConfig)} (native) and ${JSON.stringify(jsConfig)} (js)`) | ||
|
||
// clear persistent data | ||
console.error('[Bugsnag ScenarioLauncher] clearing persistent data') | ||
NativeModules.BugsnagTestInterface.clearPersistentData() | ||
|
||
// start the native client | ||
console.error('[Bugsnag ScenarioLauncher] starting native Bugsnag') | ||
await NativeModules.BugsnagTestInterface.startBugsnag(nativeConfig) | ||
|
||
// start the js client | ||
console.error('[Bugsnag ScenarioLauncher] starting js Bugsnag') | ||
Bugsnag.start(jsConfig) | ||
|
||
// run the scenario | ||
console.error('launching scenario') | ||
setTimeout(() => { | ||
scenario.run() | ||
if (typeof setScenario === 'function') setScenario(scenario) | ||
}, 1) | ||
} | ||
|
||
async function startBugsnag (scenarioName, apiKey, notifyEndpoint, sessionEndpoint, scenarioData) { | ||
console.error(`[Bugsnag ScenarioLauncher] starting Bugsnag for scenario: ${scenarioName}`) | ||
const nativeConfig = { | ||
apiKey, | ||
autoTrackSessions: false, | ||
endpoints: { | ||
notify: notifyEndpoint, | ||
sessions: sessionEndpoint | ||
} | ||
} | ||
|
||
const jsConfig = {} | ||
|
||
// create the scenario and allow it to modify the configuration | ||
// eslint-disable-next-line no-unused-vars | ||
const scenario = new Scenarios[scenarioName](nativeConfig, jsConfig, scenarioData) | ||
|
||
console.error(`[Bugsnag ScenarioLauncher] with config: ${JSON.stringify(nativeConfig)} (native) and ${JSON.stringify(jsConfig)} (js)`) | ||
|
||
// start the native client | ||
console.error('[Bugsnag ScenarioLauncher] starting native Bugsnag') | ||
await NativeModules.BugsnagTestInterface.startBugsnag(nativeConfig) | ||
|
||
// start the js client | ||
console.error('[Bugsnag ScenarioLauncher] starting js Bugsnag') | ||
Bugsnag.start(jsConfig) | ||
} | ||
|
||
export async function launchScenario (setScenario) { | ||
const command = await getCurrentCommand() | ||
|
||
switch (command.action) { | ||
case 'run-scenario': | ||
// eslint-disable-next-line no-return-await | ||
return await runScenario( | ||
command.scenario_name, | ||
command.api_key, | ||
command.notify, | ||
command.sessions, | ||
command.scenario_data, | ||
setScenario | ||
) | ||
|
||
case 'start-bugsnag': | ||
// eslint-disable-next-line no-return-await | ||
return await startBugsnag( | ||
command.scenario_name, | ||
command.api_key, | ||
command.notify, | ||
command.sessions, | ||
command.scenario_data | ||
) | ||
|
||
default: | ||
throw new Error(`Unknown action '${command.action}'`) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...es/app/react_native_navigation_js/scenarios/ReactNavigationBreadcrumbsDisabledScenario.js
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 |
---|---|---|
@@ -1,8 +1,27 @@ | ||
import Scenario from './Scenario' | ||
import { Navigation } from 'react-native-navigation' | ||
import BugsnagReactNativeNavigation from '@bugsnag/plugin-react-native-navigation' | ||
|
||
export class ReactNavigationBreadcrumbsDisabledScenario extends Scenario { | ||
constructor (configuration, jsConfig) { | ||
super() | ||
configuration.enabledBreadcrumbTypes = [] | ||
jsConfig.plugins = [new BugsnagReactNativeNavigation(Navigation)] | ||
} | ||
|
||
run () { | ||
Navigation.setRoot({ | ||
root: { | ||
stack: { | ||
children: [ | ||
{ | ||
component: { | ||
name: 'Home' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.