Skip to content

feat: e2e snapshot tests #2338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 69 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
b5332c0
chore: initial work on e2e rendering tests
CDFN Jul 3, 2024
63ca90c
use proper arch in handshake message
CDFN Jul 4, 2024
91a32b3
more work
CDFN Jul 4, 2024
0189932
properly render component and improve C/S comms
CDFN Jul 4, 2024
985a861
more work
CDFN Jul 4, 2024
85895a5
basic working version with organized folders
CDFN Jul 6, 2024
8a33b0b
fix bug causing not to send response when there are more than 1 tests
CDFN Jul 6, 2024
7ce79aa
basic version of e2e tests
CDFN Jul 8, 2024
3813852
reorganize code little bit
CDFN Jul 8, 2024
8d5d2af
ios e2e tests support
CDFN Jul 8, 2024
0f9456c
fix fabric support, add os and arch to diff name
CDFN Jul 9, 2024
a4dfc2f
remove note for self, add comment about hardcoding deviceScaleFactor
CDFN Jul 9, 2024
e69d098
fix incorrect method signature in react-native-view-shot spec
CDFN Jul 9, 2024
a4e47f1
Merge remote-tracking branch 'upstream/main' into feat/e2e
CDFN Jul 9, 2024
1d5229c
add readme section about testing
CDFN Jul 9, 2024
3ced4ba
formatting changes
CDFN Jul 9, 2024
285edf8
fix app not starting after structure changes, add rendered images to …
CDFN Jul 10, 2024
a2e34a0
fix jest not shutting down after running all tests
CDFN Jul 10, 2024
c9836f7
fix: fix format-js task to reflect changes made to folder structure
CDFN Jul 10, 2024
971f05b
add html test reports
CDFN Jul 10, 2024
4dbeeea
correct test examples
CDFN Jul 10, 2024
f779711
add platform data to each test
CDFN Jul 10, 2024
dab53da
fix platform info
CDFN Jul 10, 2024
f1d9156
reorganize adding attachments
CDFN Jul 10, 2024
dd08f40
improve UX, graceful WS connection closing
CDFN Jul 10, 2024
2205082
move testing info from readme to contributing
CDFN Jul 10, 2024
0ceaef3
Merge branch 'main' into feat/e2e
CDFN Jul 15, 2024
7dc90ad
open E2E view when E2E env is set, improve naming
CDFN Jul 15, 2024
75c8c10
test e2e
CDFN Jul 15, 2024
d2d1554
remvoe non-existing task
CDFN Jul 15, 2024
95a72af
increase timeout so tests can be run on CI, fix file not found error
CDFN Jul 16, 2024
3b4f2ce
add auto connect
CDFN Jul 16, 2024
8e950f9
remove logs
CDFN Jul 16, 2024
6ee15ce
fix babel plugin order
CDFN Jul 16, 2024
746d636
e2e CI tests
CDFN Jul 29, 2024
db00b06
Merge remote-tracking branch 'upstream/main' into feat/e2e
CDFN Jul 29, 2024
ce3041a
add gitignore
CDFN Jul 29, 2024
3ce7a8b
Merge remote-tracking branch 'upstream/main' into feat/e2e
CDFN Jul 29, 2024
f76fc0a
Merge remote-tracking branch 'upstream/main' into feat/e2e
CDFN Jul 31, 2024
69326a1
chore: move workflows from disabled folder
bohdanprog Jul 31, 2024
573b774
feat: update workflows for e2e
bohdanprog Jul 31, 2024
c8278e2
feat: add types in TestingView component
bohdanprog Jul 31, 2024
93fd82c
chore: remove unused imports
bohdanprog Jul 31, 2024
62ef5ca
feat: add new test case
bohdanprog Jul 31, 2024
e286f04
feat: move GeneralSvgRenderingTest.spec.tsx to global tests folder an…
bohdanprog Jul 31, 2024
bcf8895
feat: add comment in helpers.ts
bohdanprog Jul 31, 2024
511c153
feat: add support failed cases
bohdanprog Aug 7, 2024
63615c7
Merge remote-tracking branch 'origin' into feat/e2e
bohdanprog Aug 7, 2024
bac2823
feat: add ability to set failer cases and add separate functionality …
bohdanprog Aug 7, 2024
bbd1399
feat: rename file with failed cases, add function to read and update …
bohdanprog Aug 8, 2024
3e43665
chore: change file path
bohdanprog Aug 8, 2024
ccb1575
chore: add null check type to storeFailedResult
bohdanprog Aug 8, 2024
9dbfada
feat: add Platform-specific extensions
bohdanprog Aug 13, 2024
3d6da8f
feat: update tsconfig.json and update import in examples.tsx
bohdanprog Aug 13, 2024
af05406
fix: remove unnecesary files, and spicify platform
bohdanprog Aug 13, 2024
9319f5d
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog Aug 13, 2024
facee74
feat: add new patch pachage react-native-view-shot fix for windows pl…
bohdanprog Aug 13, 2024
2624275
feat: update workflow for windows
bohdanprog Aug 13, 2024
1006d67
fix: restore changes with library patch
bohdanprog Aug 13, 2024
8bef9b9
fix: remove TestinView for windows platform
bohdanprog Aug 14, 2024
6d7156f
chore: remove changes in tscofig
bohdanprog Aug 14, 2024
d88a6ef
fix: restore react-native-view patch
bohdanprog Aug 19, 2024
d4899d6
feat: update example apps
bohdanprog Aug 19, 2024
e490534
fix: web-example app
bohdanprog Aug 19, 2024
df4fbec
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog Aug 19, 2024
4752283
fix: hide E2E tests on Web and MacOS
jakex7 Aug 20, 2024
479c5fa
chore: disable E2E tests on main
jakex7 Aug 20, 2024
35efe7d
Merge branch 'main' of github.com:software-mansion/react-native-svg i…
bohdanprog Aug 23, 2024
6b497a7
feat: update podfile.lock files
bohdanprog Aug 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/android-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Test Android e2e
on:
pull_request:
paths:
- '.github/workflows/android-e2e-test.yml'
- 'apps/examples/**'
- 'example/**'
- 'android/**'
- 'src/**'
- 'e2e/**'
- 'package.json'
push:
branches:
- main
workflow_dispatch:
jobs:
test:
runs-on: macos-12
timeout-minutes: 60
env:
WORKING_DIRECTORY: example
API_LEVEL: 34
SYSTEM_IMAGES: system-images;android-34;google_apis;x86_64
AVD_NAME: rn-svg-avd
concurrency:
group: android-e2e-example-${{ github.ref }}
cancel-in-progress: true
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'zulu'
cache: 'gradle'
- name: Install NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r26d
local-cache: true
- name: Set ANDROID_NDK
run: echo "ANDROID_NDK=$ANDROID_HOME/ndk-bundle" >> $GITHUB_ENV
- name: Cache SDK image
id: cache-sdk-img
uses: actions/cache@v3
with:
path: $ANDROID_HOME/system-images/
key: ${{ runner.os }}-build-system-images-${{ env.SYSTEM_IMAGES }}
- name: SKDs - download required images
if: ${{ steps.cache-sdd-img.outputs.cache-hit != 'true' }}
run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "system-images;android-34;google_apis;x86_64"
- name: Cache AVD
id: cache-avd
uses: actions/cache@v3
with:
path: ~/.android/avd/${{ env.AVD_NAME }}.avd
key: ${{ runner.os }}-avd-images-${{ env.SYSTEM_IMAGES }}-${{ env.AVD_NAME }}
- name: Emulator - Create
if: ${{ steps.cache-avd.outputs.cache-hit != 'true' }}
run: $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager create avd -n ${{ env.AVD_NAME }} --device 28 --package "${{ env.SYSTEM_IMAGES }}" --sdcard 512M
- name: Emulator - Set screen settings
if: ${{ steps.cache-avd.outputs.cache-hit != 'true' }}
run: |
echo "AVD config path: $HOME/.android/avd/${{ env.AVD_NAME }}.avd/config.ini"
sed -i '' 's/.*hw\.lcd\.density.*/hw\.lcd\.density = 480/g' $HOME/.android/avd/${{ env.AVD_NAME }}.avd/config.ini
sed -i '' 's/.*hw\.lcd\.width.*/hw\.lcd\.width = 1344/g' $HOME/.android/avd/${{ env.AVD_NAME }}.avd/config.ini
sed -i '' 's/.*hw\.lcd\.height.*/hw\.lcd\.height = 2992/g' $HOME/.android/avd/${{ env.AVD_NAME }}.avd/config.ini
- name: Emulator - Boot
run: $ANDROID_HOME/emulator/emulator -memory 4096 -avd ${{ env.AVD_NAME }} -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim &

- name: ADB Wait For Device
run: adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'
timeout-minutes: 10

- name: Reverse TCP
working-directory: ${{ env.WORKING_DIRECTORY }}
run: adb devices | grep '\t' | awk '{print $1}' | sed 's/\\s//g' | xargs -I {} adb -s {} reverse tcp:8081 tcp:8081

- name: Install root node dependencies
run: yarn

- name: Install example app node dependencies
run: yarn
working-directory: ${{ env.WORKING_DIRECTORY }}

- name: Build Android app
working-directory: ${{ env.WORKING_DIRECTORY }}/android
run: ./gradlew assembleDebug

- name: Start Metro server
working-directory: ${{ env.WORKING_DIRECTORY }}
run: E2E=true yarn start &> output.log &

- name: Install APK
run: adb install -r ${{ env.WORKING_DIRECTORY }}/android/app/build/outputs/apk/debug/app-debug.apk

- name: Launch APK
run: 'while ! (adb shell monkey -p com.example 1 | grep -q "Events injected: 1"); do sleep 1; echo "Retrying due to errors in previous run..."; done'

- name: Run e2e Tests
run: E2E=true yarn e2e

- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: report
path: |
report.html
jest-html-reporters-attach/

- name: Kill emulator (so it can be cached safely)
run: adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done
93 changes: 93 additions & 0 deletions .github/workflows/ios-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Test iOS e2e
on:
pull_request:
paths:
- '.github/workflows/android-e2e-test.yml'
- 'apps/examples/**'
- 'example/**'
- 'apple/**'
- 'src/**'
- 'e2e/**'
- 'package.json'
push:
branches:
- main
workflow_dispatch:
jobs:
test:
runs-on: macos-14
timeout-minutes: 60
env:
WORKING_DIRECTORY: example
DEVICE: iPhone 14 Pro
XCODE_VERSION: latest-stable
concurrency:
group: ios-e2e-example-${{ github.ref }}
cancel-in-progress: true
steps:
- name: checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Use latest stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ env.XCODE_VERSION }}

- name: Restore react-native-svg node_modules from cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node-modules-svg-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-svg-

- name: Install react-native-svg node_modules
run: yarn install --frozen-lockfile

- name: Restore app node_modules from cache
uses: actions/cache@v3
with:
path: ${{ env.WORKING_DIRECTORY }}/node_modules
key: ${{ runner.os }}-node-modules-${{ env.WORKING_DIRECTORY }}-${{ hashFiles(format('{0}/yarn.lock', env.WORKING_DIRECTORY)) }}
restore-keys: ${{ runner.os }}-node-modules-${{ env.WORKING_DIRECTORY }}-

- name: Install app node_modules
working-directory: ${{ env.WORKING_DIRECTORY }}
run: yarn install --frozen-lockfile

- name: Restore Pods from cache
uses: actions/cache@v3
with:
path: |
${{ env.WORKING_DIRECTORY }}/ios/Pods
~/Library/Caches/CocoaPods
~/.cocoapods
key: ${{ runner.os }}-pods-${{ env.WORKING_DIRECTORY }}-${{ hashFiles(format('{0}/ios/Podfile.lock', env.WORKING_DIRECTORY)) }}

- name: Install Pods
working-directory: ${{ env.WORKING_DIRECTORY }}/ios
run: pod install

- name: Restore build artifacts from cache
uses: actions/cache@v3
with:
path: ~/Library/Developer/Xcode/DerivedData
key: ${{ runner.os }}-ios-derived-data-${{ env.WORKING_DIRECTORY }}-${{ hashFiles(format('{0}/ios/Podfile.lock', env.WORKING_DIRECTORY)) }}
- name: Start Metro server
working-directory: ${{ env.WORKING_DIRECTORY }}
run: E2E=true yarn start &> output.log &

- name: Build app
working-directory: ${{ env.WORKING_DIRECTORY }}
run: E2E=true npx react-native@latest run-ios --simulator="${{ env.DEVICE }}" --mode Debug --verbose

- name: Run e2e Tests
run: E2E=true yarn e2e

- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: report
path: |
report.html
jest-html-reporters-attach/
2 changes: 1 addition & 1 deletion .github/workflows/windows-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:

- name: Build app
working-directory: ${{ matrix.working-directory }}/windows
run: npx react-native run-windows --logging --no-packager --no-deploy
run: npx react-native run-windows --logging --no-packager --no-deploy --no-autolink
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@ experimental/

# VS Code
.vscode/

jest-html-reporters-attach/
report.html
44 changes: 37 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Contributing to React Native Svg

Thank you for helping out with react-native-svg!
We'd like to make contributions as pleasant as possible, so here's a small guide of how we see it. Happy to hear your feedback about anything, so please let us know.
We'd like to make contributions as pleasant as possible, so here's a small guide of how we see it. Happy to hear your
feedback about anything, so please let us know.

### Modifying react-native-svg

Expand All @@ -13,24 +14,51 @@ We'd like to make contributions as pleasant as possible, so here's a small guide

### Testing your changes

Add test example in [tests-example](https://github.com/react-native-svg/react-native-svg/tree/main/tests-example) concerning your change following the convention of `TestX.tsx` where `X` is your PR number.
Add test example in [tests-example](https://github.com/react-native-svg/react-native-svg/tree/main/tests-example)
concerning your change following the convention of `TestX.tsx` where `X` is your PR number.

## Tests

We use `typescript` for type checks, `eslint` with `prettier` for linting/formatting. All tests are run by github actions for all opened pull requests.
We use `typescript` for type checks, `eslint` with `prettier` for linting/formatting. All tests are run by github
actions for all opened pull requests.

- `yarn test`: Run all tests, except for e2e (see note below).
- `yarn lint`: Run `eslint` check.
- `yarn tsc`: Run `typescript` check.
- `yarn jest`: Run `jest` type check.
- `yarn e2e`: Run E2E tests (see section below)

Currently e2e tests exist here: https://github.com/msand/react-native-svg-e2e/
### Running E2E tests:

> [!WARNING]
> Reference images in this repository are generated with [pixel ratio](https://reactnative.dev/docs/pixelratio) = `3`.
> Make sure to run tests on a device that also has pixel ratio equal 3. Otherwise tests will fail.
> In order to use device with different pixel ratio, adjust it in `e2e/generateRefereces.ts` viewport and regenerate
> references.

1. Navigate to the example application's directory and initiate the Metro server using the yarn start command.
2. To run the example application on your preferred platform (note: currently only Android and iOS are supported),
execute the command `yarn android` or `yarn ios` within the example app's directory.
3. Start the Jest server by running `yarn e2e` in the project's root directory.
4. In the example application, select the E2E tab.
5. Allow the tests to complete.
6. The test results, along with any differences (i.e. the actual rendered svg versus the reference image), can be viewed
in the `e2e/diffs` directory.

### To add new E2E test cases, proceed as follows:

1. Put an SVG file of your selection into the `e2e/cases` directory.
2. Execute `yarn generateE2eRefrences`. This action launches a headless Chrome browser via Puppeteer, capturing
snapshots of all rendered SVGs as .png files. These files will serve as a reference during testing.
3. Check the `e2e/references` directory to observe newly created .png files.
4. When you rerun the E2E tests, the new test case(s) you've added will be incorporated.

## Sending a pull request

When you're sending a pull request:

- Communication is a key. If you want fix/add something, please consider either opening a new issue or finding an existing one so we can further discuss it.
- Communication is a key. If you want fix/add something, please consider either opening a new issue or finding an
existing one so we can further discuss it.
- We prefer small pull requests focused on one change, as those are easier to test/check.
- Please make sure that all tests are passing on your local machine.
- Follow the template when opening a PR.
Expand All @@ -43,7 +71,8 @@ Most notably prefixes you'll see:

- **fix**: Bug fixes
- **feat**: New feature implemented
- **chore**: Changes that are not affecting end user (CI config changes, scripts, ["grunt work"](https://stackoverflow.com/a/26944812/3510245))
- **chore**: Changes that are not affecting end user (CI config changes,
scripts, ["grunt work"](https://stackoverflow.com/a/26944812/3510245))
- **docs**: Documentation changes.
- **perf**: A code change that improves performance.
- **refactor**: A code change that neither fixes a bug nor adds a feature.
Expand All @@ -55,7 +84,8 @@ We use [release-it](https://github.com/release-it/release-it) to release new ver

## Reporting issues

You can report issues on our [bug tracker](https://github.com/react-native-community/react-native-svg/issues). Please search for existing issues and follow the issue template when opening one.
You can report issues on our [bug tracker](https://github.com/react-native-community/react-native-svg/issues). Please
search for existing issues and follow the issue template when opening one.

## License

Expand Down
Loading
Loading