Nenhuma descrição

test.sh 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. set -e
  3. TEST_APP_NAME='RNFetchBlobTest'
  4. TEST_APP_PATH="$(pwd)/${TEST_APP_NAME}"
  5. TARGET='android'
  6. CWD=$(pwd)
  7. if [ "$#" -eq 1 ]; then
  8. if [ "$1" == 'android' ]; then
  9. TARGET="$1"
  10. echo 'start android test'
  11. elif [ "$1" == 'ios' ]; then
  12. TARGET="$1"
  13. echo 'start ios test'
  14. else
  15. exit "unrecongized target platform $1, please specify a target platform `ios` or `android`."
  16. fi
  17. elif [ "$#" -gt 2 ] && [ "$1" == 'path' ]; then
  18. TEST_APP_PATH="$2"
  19. TARGET="$3"
  20. echo "use exist test app path=$2 target=$3"
  21. else
  22. exit "unrecongized arguments."
  23. fi
  24. # Create new rn project
  25. if [ "$#" -eq 1 ]; then
  26. echo 'creating test app RNFetchBlobTest ..'
  27. react-native init "${TEST_APP_NAME}"
  28. fi
  29. # copy js files to test app folder
  30. cp -R test/ "${TEST_APP_PATH}/"
  31. node -e "var fs=require('fs'); var pkg = JSON.parse(fs.readFileSync('./RNFetchBlobTest/package.json')); pkg.rnpm = {assets : ['assets']}; fs.writeFileSync('./RNFetchBlobTest/package.json', JSON.stringify(pkg, null, 4));"
  32. # install module
  33. cd "${TEST_APP_PATH}"
  34. # npm install --save "${CWD}/src"
  35. npm install --save react-native-fetch-blob
  36. # libs that requires web API polyfills
  37. npm install --save firebase
  38. react-native link
  39. # copy android assets
  40. cd ${CWD}
  41. cp -R ./test/assets/ ./RNFetchBlobTest/android/app/src/main/assets/
  42. # start RN
  43. cd "${TEST_APP_PATH}"
  44. if [ "$#" == 4 ]; then
  45. sed -i.bak "s/${TEST_APP_NAME}/$4/" ./index.test.js
  46. fi
  47. react-native "run-${TARGET}"
  48. # install dev packages
  49. cd ${CWD}
  50. npm install
  51. # start test server
  52. cd "${CWD}/test-server"
  53. # kill existing server
  54. kill "$(lsof | grep :8123 | awk '{ printf $2 }')"
  55. node server