Skip to content

Commit cbb99ff

Browse files
committed
test: 🧪 add http errors e2e tests
1 parent 67e90ec commit cbb99ff

6 files changed

Lines changed: 64 additions & 1 deletion

File tree

scripts/generate-react-native-fixture.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const replacementFilesDir = resolve(ROOT_DIR, 'test/react-native/features/fixtur
4040

4141
const INTERNAL_DEPENDENCIES = [
4242
'@bugsnag/react-native',
43-
'@bugsnag/request-tracker'
43+
'@bugsnag/request-tracker',
44+
'@bugsnag/plugin-network-instrumentation'
4445
]
4546

4647
// make sure we install a compatible versions of peer dependencies
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"message": "^401: .*\/reflect\/[?]status=401$",
4+
"errorClass": "HTTPError",
5+
"type": "reactnativejs",
6+
"stacktrace": "IGNORE"
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"message": "^500: .*\/reflect\/[?]status=500$",
4+
"errorClass": "HTTPError",
5+
"type": "reactnativejs",
6+
"stacktrace": "IGNORE"
7+
}
8+
]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Scenario from './Scenario'
2+
import BugsnagPluginNetworkInstrumentation from '@bugsnag/plugin-network-instrumentation'
3+
4+
export class NetworkRequestScenario extends Scenario {
5+
constructor (nativeConfig, jsConfig, scenarioData) {
6+
super()
7+
this.reflectEndpoint = nativeConfig.endpoints.notify.replace('/notify', '/reflect')
8+
this.statusCode = scenarioData
9+
10+
const plugin = new BugsnagPluginNetworkInstrumentation({
11+
maxRequestSize: 1024,
12+
maxResponseSize: 1024
13+
})
14+
15+
jsConfig.plugins = jsConfig.plugins || []
16+
jsConfig.plugins.push(plugin)
17+
}
18+
19+
run () {
20+
const url = new URL(this.reflectEndpoint)
21+
url.searchParams.append('status', this.statusCode)
22+
fetch(url)
23+
}
24+
}

test/react-native/features/fixtures/scenario-launcher/scenarios/core/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,6 @@ export { ReactNativeErrorBoundaryScenario } from './ReactNativeErrorBoundaryScen
8181
// grouping-discriminator.feature
8282
export { GroupingDiscriminatorScenario } from './GroupingDiscriminatorScenario'
8383
export { GroupingDiscriminatorNativeScenario } from './GroupingDiscriminatorNativeScenario'
84+
85+
// http_errors.feature
86+
export { NetworkRequestScenario } from './NetworkRequestScenario'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Feature: HTTP Errors
2+
3+
Scenario Outline: Error is reported for network requests with error status code
4+
When I run "NetworkRequestScenario" with data "<status_code>"
5+
And I wait to receive an error
6+
Then the error payload field "events.0.context" matches the regex "^GET [0-9.]*:[0-9]{4}$"
7+
And the error payload field "events.0.exceptions" matches the JSON fixture in "features/fixtures/expected_http_errors/<status_code>.json"
8+
Examples:
9+
| status_code |
10+
| 401 |
11+
| 500 |
12+
13+
Scenario Outline: Error is not reported for successful network requests
14+
When I run "NetworkRequestScenario" with data "<status_code>"
15+
Then I should receive no errors
16+
Examples:
17+
| status_code |
18+
| 200 |
19+
| 307 |

0 commit comments

Comments
 (0)