Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Feb 21, 2024
1 parent 443c58e commit 455400e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 49 deletions.
55 changes: 7 additions & 48 deletions tests/e2e/ADDING_TESTS.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
# Adding new E2E Tests

## Running your new test in development mode

Typically you'd run all the tests with `npm run test:e2e` on your machine.
This will run the tests with some local settings, however that is not
optimal when you add a new test for which you want to quickly test if it works, as the prior command
still runs the release version of the app, which is hard to debug.

I recommend doing the following.

1. We need to compile a android development app version that has capturing metrics enabled:
```bash
# Make sure that your .env file is the one we need for e2e testing:
cp ./tests/e2e/.env.e2e .env

# Build the android app like you normally would with
npm run android
```
2. Rename `./index.js` to `./appIndex.js`
3. Create a new `./index.js` with the following content:
```js
require('./src/libs/E2E/reactNativeLaunchingTest');
```
4. In `./src/libs/E2E/reactNativeLaunchingTest.ts` change the main app import to the new `./appIndex.js` file:
```diff
- import '../../../index';
+ import '../../../appIndex';
```

> [!WARNING]
> Make sure to not commit these changes to the repository!
Now you can start the metro bundler in e2e mode with:

```bash
CAPTURE_METRICS=true E2E_TESTING=true npm start -- --reset-cache
```

Then we can execute our test with:

```
npm run test:e2e:dev -- --includes "My new test name"
```

> - `--includes "MyTestName"` will only run the test with the name "MyTestName", but is optional

## Creating a new test

Tests are executed on device, inside the app code.
Expand Down Expand Up @@ -144,8 +98,13 @@ Done! When you now start the test runner, your new test will be executed as well

## Quickly test your test

To check your new test you can simply run `npm run test:e2e`, which uses the
`--development` flag. This will run the tests on the branch you are currently on, runs fewer iterations and most importantly, it tries to reuse the existing APK and just patch into the new app bundle, instead of rebuilding the release app from scratch.
> [!TIP]
> You can only run a specific test by specifying the `--includes` flag:
> ```sh
> npm run test:e2e:dev -- --includes "My new test name"
> ```
It is recommended to run a debug build of the e2e tests first to iterate quickly on your test. Follow the explanation in the [README](./README.md) to create a debug build.
## Debugging your test
Expand Down
15 changes: 14 additions & 1 deletion tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,20 @@ cp ./tests/e2e/.env.e2e .env
npm run android
```

3. Run the tests using the dev command:
3. We need to modify the app entry to point to the one for the tests. Therefore rename `./index.js` to `./appIndex.js` temporarily.

4. Create a new `./index.js` with the following content:
```js
require('./src/libs/E2E/reactNativeLaunchingTest');
```

5. In `./src/libs/E2E/reactNativeLaunchingTest.ts` change the main app import to the new `./appIndex.js` file:
```diff
- import '../../../index';
+ import '../../../appIndex';
```

6. You can now run the tests. This command will invoke the test runner:

```sh
npm run test:e2e:dev
Expand Down

0 comments on commit 455400e

Please sign in to comment.