Skip to content

Commit

Permalink
feat: adding e2e tests, build automation and linting (#174)
Browse files Browse the repository at this point in the history
* Added lint-staged with pre-commit hooks to have more consistent code styling. 
* Integrated the test app into this repository
* Added simple end to end tests for the test app
* Using Github Actions for CI/CD
* Using semantic-release for fully automated version management and package publishing
  • Loading branch information
reime005 committed Mar 22, 2020
1 parent 21dad7b commit d0ee16e
Show file tree
Hide file tree
Showing 89 changed files with 16,701 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
example/RNBackgroundExample/node_modules
example/RNBackgroundExample/e2e
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect -->

# Summary

<!--
Explain the **motivation** for making this change: here are some points to help you:
* What issues does the pull request solve? Please tag them so that they will get automatically closed once the PR is merged
* What is the feature? (if applicable)
* How did you implement the solution?
* What areas of the library does it impact?
-->

## Test Plan

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

### What's required for testing (prerequisites)?

### What are the steps to reproduce (after prerequisites)?

## Compatibility

| OS | Implemented |
| ------- | :---------: |
| iOS | ✅❌ |
| Android | ✅❌ |

## Checklist

<!-- Check completed item, when applicable, via: [X] -->

- [ ] I have tested this on a device and a simulator
- [ ] I added the documentation in `README.md`
- [ ] I updated the typed files (TS and Flow)
- [ ] I've added Detox End-to-End Test(s)
- [ ] I've created a snack to demonstrate the changes: LINK HERE
62 changes: 62 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test Android Example App

on: [push, pull_request]

jobs:
react-native-android:
runs-on: macos-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: Checkout project
uses: actions/checkout@v1

- name: Specify node version
uses: actions/setup-node@v1
with:
node-version: 12

- name: Use specific Java version for sdkmanager to work
uses: joschi/setup-jdk@v1
with:
java-version: 'openjdk8'
architecture: 'x64'

- name: Setup Android emulator
run: |
echo y | sudo $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-28;google_apis;x86" > /dev/null
$ANDROID_HOME/tools/bin/avdmanager -s create avd -n emu -k "system-images;android-28;google_apis;x86" -b "x86" -c 1G -d 7 -f
- name: Install node_modules
working-directory: example/RNBackgroundExample/
run:
yarn install --frozen-lockfile

- name: Deploy
working-directory: example/RNBackgroundExample/
run:
yarn e2e/deploy/android

- name: Start Emulator
working-directory: example/RNBackgroundExample/
timeout-minutes: 5
run: |
export PATH=$PATH:$ANDROID_HOME/platform-tools
$ANDROID_HOME/emulator/emulator @emu -noaudio -no-boot-anim -netdelay none -accel on -no-snapshot &
adb wait-for-device; adb shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;'; adb shell wm dismiss-keyguard
- name: Android test
working-directory: example/RNBackgroundExample/
timeout-minutes: 8
run: |
mkdir -p ./artifacts
node e2e/start-server.js &
adb reverse tcp:8080 tcp:8080
yarn e2e/test/android --record-videos failing
- uses: actions/upload-artifact@master
name: Provide videos of failed E2E tests
if: failure()
with:
name: android-failing-e2e-videos
path: example/RNBackgroundExample/artifacts
28 changes: 28 additions & 0 deletions .github/workflows/deploy-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy & Release

on:
push:
branches:
- master

jobs:
deploy-release:
runs-on: macos-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: Checkout project
uses: actions/checkout@v1

- name: Specify node version
uses: actions/setup-node@v1
with:
node-version: 12

- name: Release to NPM
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
yarn install --frozen-lockfile
npx semantic-release
40 changes: 40 additions & 0 deletions .github/workflows/iOS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test iOS Example App

on: [push, pull_request]

jobs:
react-native-ios:
runs-on: macos-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: Checkout project
uses: actions/checkout@v1

- name: Specify node version
uses: actions/setup-node@v1
with:
node-version: 12

- name: Setup Detox
run: |
brew tap wix/brew
brew install applesimutils
- name: Install node_modules
working-directory: example/RNBackgroundExample/
run:
yarn install --frozen-lockfile

- name: Deploy
working-directory: example/RNBackgroundExample/
run:
yarn deploy/release/ios

- name: iOS test
working-directory: example/RNBackgroundExample/
timeout-minutes: 8
run: |
npx detox clean-framework-cache && npx detox build-framework-cache
node e2e/start-server.js &
yarn e2e/test/ios
24 changes: 24 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Node Environment

on: [push, pull_request]

jobs:
node-lint-tests:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: checkout
uses: actions/checkout@v1

- name: setup node
uses: actions/setup-node@v1
with:
node-version: 12

- name: install node_modules
run: yarn install --frozen-lockfile

- name: node lint
run:
yarn lint:ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DerivedData
*.ipa
*.xcuserstate
project.xcworkspace
Pods/

# Android/IntelliJ
#
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bracketSpacing: true,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Since Version > 5.3.0 we follow semantic versioning.

See the [releases](https://github.com/Vydia/react-native-background-upload/releases) page on GitHub for information regarding each release.
File renamed without changes.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# react-native-background-upload [![npm version](https://badge.fury.io/js/react-native-background-upload.svg)](https://badge.fury.io/js/react-native-background-upload)


![GitHub Actions status](https://github.com/Vydia/react-native-background-upload/workflows/iOS/badge.svg)

![GitHub Actions status](https://github.com/Vydia/react-native-background-upload/workflows/android/badge.svg)

The only React Native http post file uploader with android and iOS background support. If you are uploading large files like videos, use this so your users can background your app during a long upload.

NOTE: Use major version 4 with RN 47.0 and greater. If you have RN less than 47, use 3.0. To view all available versions:
Expand Down Expand Up @@ -79,7 +85,7 @@ No further actions required.

## 3. Expo

To use this library with [Expo](https://expo.io) one must first detach (eject) the project and follow [step 2](#2-link-native-code) instructions. Additionally on iOS there is a must to add a Header Search Path to other dependencies which are managed using Pods. To do so one has to add `$(SRCROOT)/../../../ios/Pods/Headers/Public` to Header Search Path in `VydiaRNFileUploader` module using XCode.
To use this library with [Expo](https://expo.io) one must first detach (eject) the project and follow [step 2](#2-link-native-code) instructions. Additionally on iOS there is a must to add a Header Search Path to other dependencies which are managed using Pods. To do so one has to add `$(SRCROOT)/../../../ios/Pods/Headers/Public` to Header Search Path in `VydiaRNFileUploader` module using XCode.

# Usage

Expand Down Expand Up @@ -146,7 +152,7 @@ All top-level methods are available as named exports or methods on the default e

### startUpload(options)

The primary method you will use, this starts the upload process.
The primary method you will use, this starts the upload process.

Returns a promise with the string ID of the upload. Will reject if there is a connection problem, the file doesn't exist, or there is some other problem.

Expand Down Expand Up @@ -292,7 +298,7 @@ Is there an example/sandbox app to test out this package?

> Yes, there is a simple react native app that comes with an [express](https://github.com/expressjs/express) server where you can see react-native-background-upload in action and try things out in an isolated local environment.
[ReactNativeBackgroundUploadExample](https://github.com/Vydia/ReactNativeBackgroundUploadExample)
[RNBackgroundExample](https://github.com/Vydia/react-native-background-upload/blob/master/example/RNBackgroundExample)

Does it support iOS camera roll assets?

Expand Down
6 changes: 6 additions & 0 deletions example/RNBackgroundExample/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
4 changes: 4 additions & 0 deletions example/RNBackgroundExample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
75 changes: 75 additions & 0 deletions example/RNBackgroundExample/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore polyfills
node_modules/react-native/Libraries/polyfills/.*

; These should not be required directly
; require from fbjs/lib instead: require('fbjs/lib/warning')
node_modules/warning/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/

[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

munge_underscores=true

module.name_mapper='^react-native$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/react-native/react-native-implementation'
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
inexact-spread=warn
unnecessary-invariant=warn
signature-verification-failure=warn
deprecated-utility=error

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.105.0
1 change: 1 addition & 0 deletions example/RNBackgroundExample/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -text
Loading

0 comments on commit d0ee16e

Please sign in to comment.