-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathScenarioLauncher.js
More file actions
102 lines (83 loc) · 3.11 KB
/
ScenarioLauncher.js
File metadata and controls
102 lines (83 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
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
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
import * as Scenarios from '../scenarios'
import { getCurrentCommand } from './CommandRunner'
import { NativeInterface } from './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)
// clear persistent data
console.error('[Bugsnag ScenarioLauncher] clearing persistent data')
NativeInterface.clearPersistentData()
// start the native client
console.error('[Bugsnag ScenarioLauncher] starting native Bugsnag')
await NativeInterface.startBugsnag(nativeConfig)
// The calls between starting the native client and starting the js client
// Are typically longer than we see here, so we add a delay to ensure the
// native client is fully initialised before the js client is started
await new Promise(resolve => setTimeout(resolve, 50))
// 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 scenario.view === '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 NativeInterface.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':
return await runScenario(
command.scenario_name,
command.api_key,
command.notify,
command.sessions,
command.scenario_data,
setScenario
)
case 'start-bugsnag':
return await startBugsnag(
command.scenario_name,
command.api_key,
command.notify,
command.sessions,
command.scenario_data
)
default:
throw new Error(`Unknown action '${command.action}'`)
}
}