react-native-navigation的迁移库

e2e.ios.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const _ = require('lodash');
  2. const shellUtils = require('shell-utils');
  3. const fs = require('fs');
  4. const release = _.includes(process.argv, 'release');
  5. function hackReactXcodeScript() {
  6. const fileToHack = `./node_modules/react-native/packager/react-native-xcode.sh`;
  7. const lines = _.split(String(fs.readFileSync(fileToHack)), '\n');
  8. lines[11] = release ? '' : `exit 0;`;
  9. fs.writeFileSync(fileToHack, _.join(lines, '\n'));
  10. }
  11. function buildProjForDetox() {
  12. const scheme = release ? `playground_release_Detox` : `playground_Detox`;
  13. shellUtils.exec.execSync(`./scripts/detoxDebugFix.rb ${release ? '' : 'debug'}`);
  14. shellUtils.exec.execSync(`echo 'travis_fold:start:xcodebuild'`);
  15. const cmd = `RCT_NO_LAUNCH_PACKAGER=true
  16. cd ios && xcodebuild
  17. -scheme ${scheme}
  18. ${release ? 'clean build' : 'build'}
  19. -project playground.xcodeproj
  20. -sdk iphonesimulator
  21. -derivedDataPath ./DerivedData/playground`;
  22. if (hasXcpretty()) {
  23. shellUtils.exec.execSync(`${cmd} | xcpretty && exit \${PIPESTATUS[0]}`);
  24. } else {
  25. shellUtils.exec.execSync(`${cmd}`);
  26. }
  27. shellUtils.exec.execSync(`echo 'travis_fold:end:xcodebuild'`);
  28. }
  29. function hasXcpretty() {
  30. try {
  31. return shellUtils.exec.execSyncRead(`which xcpretty`);
  32. } catch (e) {
  33. return false;
  34. }
  35. }
  36. function e2e() { //eslint-disable-line
  37. try {
  38. shellUtils.exec.execSync(`echo 'travis_fold:start:detox-ios'`);
  39. shellUtils.exec.execSyncSilent(`watchman watch-del-all || true`);
  40. shellUtils.exec.kill(`detox-server`);
  41. shellUtils.exec.exec(`./node_modules/.bin/detox-server > ./detox-server.log 2>&1`);
  42. const detoxAppBuildPath = `ios/DerivedData/playground/Build/Products/${release ? 'Release' : 'Debug'}_Detox-iphonesimulator/playground.app`;
  43. shellUtils.exec.execSync(`detoxAppBuildPath="${detoxAppBuildPath}"
  44. BABEL_ENV=test
  45. ./node_modules/mocha/bin/mocha e2e
  46. --timeout 240000
  47. --recursive
  48. --compilers js:babel-register`);
  49. } finally {
  50. shellUtils.exec.execSync(`./scripts/detoxDebugFix.rb`);
  51. shellUtils.exec.kill(`detox-server`);
  52. if (process.env.CI) {
  53. shellUtils.exec.kill(`Simulator`);
  54. shellUtils.exec.kill(`CoreSimulator`);
  55. }
  56. shellUtils.exec.execSync(`cat ./detox-server.log`);
  57. shellUtils.exec.execSync(`rm -f ./detox-server.log`);
  58. shellUtils.exec.execSync(`sleep 5`);
  59. shellUtils.exec.execSync(`echo 'travis_fold:end:detox-ios'`);
  60. }
  61. }
  62. function run() {
  63. hackReactXcodeScript();
  64. buildProjForDetox();
  65. e2e();
  66. }
  67. run();