react-native-navigation的迁移库

e2e.ios.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. const cmd = `RCT_NO_LAUNCH_PACKAGER=true
  15. cd ios && xcodebuild
  16. -scheme ${scheme} build
  17. -project playground.xcodeproj
  18. -sdk iphonesimulator
  19. -derivedDataPath ./DerivedData/playground`;
  20. if (hasXcpretty()) {
  21. shellUtils.exec.execSync(`set -o pipefail && ${cmd} | xcpretty`);
  22. } else {
  23. shellUtils.exec.execSync(`${cmd}`);
  24. }
  25. }
  26. function hasXcpretty() {
  27. try {
  28. return shellUtils.exec.execSyncRead(`which xcpretty`);
  29. } catch (e) {
  30. return false;
  31. }
  32. }
  33. function e2e() {
  34. try {
  35. shellUtils.exec.execSyncSilent(`watchman watch-del-all || true`);
  36. shellUtils.exec.kill(`detox-server`);
  37. shellUtils.exec.exec(`./node_modules/.bin/detox-server > ./detox-server.log 2>&1`);
  38. const detoxAppBuildPath = `ios/DerivedData/playground/Build/Products/${release ? 'Release' : 'Debug'}_Detox-iphonesimulator/playground.app`;
  39. shellUtils.exec.execSync(`detoxAppBuildPath="${detoxAppBuildPath}"
  40. BABEL_ENV=test
  41. ./node_modules/mocha/bin/mocha e2e
  42. --timeout 120000
  43. --recursive
  44. --compilers js:babel-register`);
  45. } finally {
  46. shellUtils.exec.execSync(`./scripts/detoxDebugFix.rb`);
  47. shellUtils.exec.kill(`detox-server`);
  48. if (release) {
  49. shellUtils.exec.kill(`Simulator`);
  50. shellUtils.exec.kill(`CoreSimulator`);
  51. }
  52. shellUtils.exec.execSync(`cat ./detox-server.log`);
  53. shellUtils.exec.execSync(`rm -f ./detox-server.log`);
  54. shellUtils.exec.execSync(`sleep 5`);
  55. }
  56. }
  57. function run() {
  58. hackReactXcodeScript();
  59. buildProjForDetox();
  60. e2e();
  61. }
  62. run();