Skip to content

Commit

Permalink
feat(app-check, expo): add config plugin for iOS module initialization (
Browse files Browse the repository at this point in the history
#7662)

* Create config plugin for App Check
* Update tests
* Update packages/app-check/plugin/__tests__/README.md
* add expo dep needed for plugin, update snapshots, auto-fix lint error

---------

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
mickeywu and mikehardy authored Mar 21, 2024
1 parent fae5966 commit c6e813e
Show file tree
Hide file tree
Showing 16 changed files with 1,189 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/app-check/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ For instructions on how to generate required keys and register an app for the de
## Initialize

> If you're using Expo Managed Workflow, you can load the `@react-native-firebase/app-check` config plugin to skip the Initialize setup step.
You must call initialize the AppCheck module prior to calling any firebase back-end services for App Check to function.

To do that, edit your `ios/ProjectName/AppDelegate.mm` and add the following two lines:
Expand Down
1 change: 1 addition & 0 deletions packages/app-check/app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build');
11 changes: 10 additions & 1 deletion packages/app-check/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
"appCheck"
],
"peerDependencies": {
"@react-native-firebase/app": "19.0.1"
"@react-native-firebase/app": "19.0.1",
"expo": ">=47.0.0"
},
"devDependencies": {
"expo": "^49.0.21"
},
"peerDependenciesMeta": {
"expo": {
"optional": true
}
},
"publishConfig": {
"access": "public"
Expand Down
19 changes: 19 additions & 0 deletions packages/app-check/plugin/__tests__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Expo Config Plugin unit tests

To test the changes to native code applied by config plugins, [snapshot tests](https://jestjs.io/docs/snapshot-testing) are used. Plugin test flow, in short:

1. A test fixture is loaded. In this case, fixtures are template files (`build.gradle`, `AppDelegate.m` etc.) from [`expo-template-bare-minimum`](https://github.com/expo/expo/tree/main/templates/expo-template-bare-minimum).
2. Plugin changes are applied (e.g. gradle dependency is added).
3. Modified file is compared with previously saved snapshot. If they're equal, the test passes. If not, the test fails and the difference (actual vs expected) is shown.

You can preview the snapshot files manually, by opening `__snapshots__/*.snap` files.

### Updating the snapshots

Snapshot tests are designed to ensure the plugin result will not change. In case you intentionally modified the plugin behavior (e.g. updated gradle dependency versions), you have to update the snapshots, otherwise the tests will fail. There are two ways to do it:

- Update all snapshots by running `npm run tests:jest -u`.
- Update snapshots interactively, one by one:
1. Run `yarn tests:jest --watchAll`
2. Press `i` to let `jest` display changes and prompt you for updating each snapshot.
> This option is not available, when there are no failing snapshots
Loading

0 comments on commit c6e813e

Please sign in to comment.