react-native-navigation的迁移库

test-snapshot.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const includes = require('lodash/includes');
  2. const exec = require('shell-utils').exec;
  3. const android = includes(process.argv, '--android');
  4. const release = includes(process.argv, '--release');
  5. const BRANCH = process.env.BRANCH;
  6. const RECORD = process.env.RECORD === 'true';
  7. function run() {
  8. if (android) {
  9. runAndroidSnapshotTests();
  10. } else {
  11. runIosSnapshotTests();
  12. }
  13. }
  14. function runAndroidSnapshotTests() {
  15. }
  16. function runIosSnapshotTests() {
  17. exec.execSync('npm run build');
  18. exec.execSync('npm run pod-install');
  19. testTarget(RECORD ? 'SnapshotRecordTests' : 'SnapshotTests', 'iPhone 11', '13.0');
  20. }
  21. function testTarget(scheme, device, OS = 'latest') {
  22. const conf = release ? `Release` : `Debug`;
  23. exec.execSync(`cd ./playground/ios &&
  24. RCT_NO_LAUNCH_PACKAGER=true
  25. xcodebuild build build-for-testing
  26. -scheme "${scheme}"
  27. -workspace playground.xcworkspace
  28. -sdk iphonesimulator
  29. -configuration ${conf}
  30. -derivedDataPath ./DerivedData/playground
  31. -quiet
  32. -UseModernBuildSystem=NO
  33. ONLY_ACTIVE_ARCH=YES`);
  34. try {
  35. exec.execSync(`cd ./playground/ios &&
  36. RCT_NO_LAUNCH_PACKAGER=true
  37. xcodebuild test-without-building
  38. -scheme "${scheme}"
  39. -workspace playground.xcworkspace
  40. -sdk iphonesimulator
  41. -configuration ${conf}
  42. -destination 'platform=iOS Simulator,name=${device},OS=${OS}'
  43. -derivedDataPath ./DerivedData/playground
  44. ONLY_ACTIVE_ARCH=YES`);
  45. } catch (error) {
  46. if (!RECORD) {
  47. throw 'Snapshot tests failed';
  48. }
  49. }
  50. finally {
  51. if (RECORD) {
  52. pushSnapshots();
  53. }
  54. }
  55. }
  56. function pushSnapshots() {
  57. setupGit();
  58. exec.execSync(`git checkout ${BRANCH}`);
  59. exec.execSync(`git add ./playground/ios/SnapshotTests/ReferenceImages_64`);
  60. exec.execSync(`git commit -m "Update snapshots [ci skip]"`);
  61. exec.execSync(`git push deploy ${BRANCH}`);
  62. }
  63. function setupGit() {
  64. exec.execSyncSilent(`git config --global push.default simple`);
  65. exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
  66. exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
  67. const remoteUrl = new RegExp(`https?://(\\S+)`).exec(exec.execSyncRead(`git remote -v`))[1];
  68. exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
  69. }
  70. run();