react-native-navigation的迁移库

test.e2e.android.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-disable no-console */
  2. const _ = require('lodash');
  3. const exec = require('shell-utils').exec;
  4. const release = _.includes(process.argv, '--release');
  5. // Run just a single test, e.g. npm test-e2e-android -- --just com.MyClass#myMethod
  6. const filter = _.chain(process.argv).dropWhile((a) => a !== '--just').take(2).last().value();
  7. run();
  8. function run() {
  9. if (process.env.CI) {
  10. console.log(`android e2e is disabled on CI until Travis will support x86 emulators or we migrate to our own solution`);
  11. } else {
  12. assertEnv();
  13. if (!isDeviceRunning()) {
  14. startEmulator();
  15. }
  16. runTests();
  17. }
  18. }
  19. function assertEnv() {
  20. if (_.isEmpty(process.env.ANDROID_HOME)) {
  21. throw new Error(`$ANDROID_HOME is not defined`);
  22. }
  23. }
  24. function isDeviceRunning() {
  25. try {
  26. const response = exec.execSyncRead(`adb -e shell getprop init.svc.bootanim 2>&1`);
  27. return _.isEqual(response, `stopped`);
  28. } catch (err) {
  29. return false;
  30. }
  31. }
  32. function startEmulator() {
  33. console.log(`Looking for avd...`);
  34. const avdsRaw = exec.execSyncRead(`${process.env.ANDROID_HOME}/tools/bin/avdmanager list avd -c`);
  35. const avdName = /^.*package\.xml(\S+)$/m.exec(avdsRaw)[1];
  36. if (_.isEmpty(avdName)) {
  37. throw new Error(`Can't find avd to launch. Please create an avd first.`);
  38. }
  39. console.log(`found avd name: ${avdName}, Launching...`);
  40. exec.execAsyncSilent(`${process.env.ANDROID_HOME}/tools/emulator -gpu host -no-audio @${avdName}`);
  41. exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
  42. }
  43. function runTests() {
  44. exec.execSync(`npm run uninstall-android`);
  45. exec.execSync(`npm run install-android ${release ? '-- --release' : ''}`);
  46. const filterParam = filter ? '-Pandroid.testInstrumentationRunnerArguments.class=' + filter : '';
  47. exec.execSync(`cd AndroidE2E && ./gradlew ${filterParam} connectedDebugAndroidTest`);
  48. }