The react-native CLI tests come in three parts:
- CLI tests, that don't require any remote connections or special setup
- Testing an app build, which requires your local machine to be set up for building iOS and Android applications
- Testing the built app, which requires the built application from the previous test set to run
The CLI tests target the command line interface by providing a set of responses to expected queries, verifying that the CLI tool responds correctly and makes appropriate changes to the workspace.
- Run through the initial setup in TESTING.md
- Run
npm pack packages/react-native-cli/
to pack the react-native-cli package - Copy the resulting package,
bugsnag-react-native-cli-{VERSION}.tgz
into the target fixture, e.g.:cp bugsnag-react-native-cli-*.tgz test/react-native-cli/features/fixtures/rn0_64
- Change directory into
test/react-native-cli
- Check the contents of
Gemfile
to select the version ofmaze-runner
to use - Install maze-runner with
bundle install
- Run the full set of cli tests targeting a specific react-native version (
rn0_61
for example):
REACT_NATIVE_VERSION=rn0_64 bundle exec maze-runner features/cli-tests
The build tests come in two flavours, Android and iOS, and are required to run the subsequent tests using the resulting .apk
and .ipa
artefacts. These tests ensure that the app can be built after Bugsnag is installed, and subsequent build messages are sent and contain the appropriate information.
- Change directory into
test/react-native-cli
- Check the contents of
Gemfile
to select the version ofmaze-runner
to use - Install maze-runner with
bundle install
- Run maze-runner targeting the specific Android build feature for a specific react-native version (
rn0_61
for example):REACT_NATIVE_VERSION=rn0_61 bundle exec maze-runner features/build-app-tests/build-android-app.feature
- Run the script to trigger the build for the specific react-native version (
rn0_62
for example):./scripts/init-and-build-test.sh rn0_62
These tests ensure that Bugsnag has successfully been installed by the CLI, and errors and sessions are correctly reported.
Before running these tests the previous tests, Build Tests
must be run for the test fixtures to be present.
- Change directory into
test/react-native-cli
- Check the contents of
Gemfile
to select the version ofmaze-runner
to use - Install maze-runner with
bundle install
Ensure that the following environment variables are set:
BROWSER_STACK_USERNAME
- Your BrowserStack App Automate UsernameBROWSER_STACK_ACCESS_KEY
- Your BrowserStack App Automate Access KeyMAZE_BS_LOCAL
- Location of the BrowserStack local testing binary
See https://www.browserstack.com/local-testing/app-automate for details of the required local testing binary. In
particular, these commands need the BrowserStackLocal
binary (available
here to reside in your home directory.
- To run on an Android device (
rn0_63
for example):bundle exec maze-runner --app=./build/rn0_63.apk \ --farm=bs \ --device=ANDROID_9_0 \ --bs-local=~/BrowserStackLocal \ features/run-app-tests
- Or on iOS:
bundle exec maze-runner --app=../../build/rn0_63.ipa \ --farm=bs \ --device=IOS_13 \ --bs-local=~/BrowserStackLocal \ features/run-app-tests
When each new version of React Native is released, a new test fixture project "shell" should be created. The inner workings of the app (that exercise the test scenarios) are then copied in dynamically by the build process. There are several steps to follow to create the project shell:
-
Add a new service to docker-compose.yml for the new fixture
-
Create a new React Native project of the desired version. E.g:
npx react-native init rn0_64 --version 0.64
-
Remove the following files/folders, if they exist:
- __tests__
- .eslintrc.js
-
Create a
.dockerignore
file:# Ignore lockfiles as they can influence test runs package-lock.json yarn.lock
-
Add the following to
.gitignore
:# Ignore lockfiles as they can influence test runs package-lock.json yarn.lock
-
Copy
App.js
from an existing fixture (overwriting that created by React Native) -
For Android:
-
In the
application
tag in app/src/main/AndroidManifest.xml, add:android:usesCleartextTraffic="true"
-
Add CrashyModule.java and CrashyPackage.java from an existing test fixture, updating the package name
-
In MainApplication.java, add:
packages.add(new CrashyPackage());
-
-
For iOS:
-
Disable Flipper by removing the following from the
Podfile
and runpod install
to regeneratePodfile.lock
. Flipper doesn't benefit the test fixture and removing it significantly speeds up the build.use_flipper!()
-
Copy the following files from an existing fixture:
ios/rn0_xx/CrashyCrashy.h
ios/rn0_xx/CrashyCrashy.m
-
Add to
rn_0_xx/Info.plist
(to the same<dict>
asNSExceptionDomains
):
<key>NSAllowsArbitraryLoads</key> <true/>
- Open the workspace and add
CrashyCrashy.h
andCrashyCrashy.m
to the project. - Set the Bugsnag development team on the project.
-