react-native-navigation的迁移库

test.e2e.android.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = _(process.argv).dropWhile((a) => a !== 'just').take(2).last();
  7. run();
  8. function run() {
  9. if (process.env.CI) {
  10. console.log(`android e2e is disabled on CI`);
  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 avds = exec.execSyncRead(`avdmanager list avd -c`);
  35. const avdName = /^.*package\.xml(\S+)$/.exec(avds)[1];
  36. if (_.isEmpty(avdName)) {
  37. throw new Error(`Launch an android emulator or connect a device`);
  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. }
  49. // const avdName = 'pixel';
  50. // const sdk = 'android-24';
  51. // const apis = 'default';
  52. // const abi = 'armeabi-v7a';
  53. // const packageName = `system-images;${sdk};${apis};${abi}`;
  54. // function installEmulator() {
  55. // exec.execSync(`sdkmanager "emulator"`);
  56. // exec.execSync(`sdkmanager "${packageName}"`);
  57. // exec.execSync(`echo no | avdmanager create avd --force --name "${avdName}" --abi "${apis}/${abi}" --package "${packageName}" --device "pixel"`);
  58. // exec.execSync(`avdmanager list avd`);
  59. // }
  60. // function launchEmulator() {
  61. // console.log(`Launching Android Emulator`);
  62. // exec.execSync(`cd $ANDROID_HOME/tools && ./emulator -skin 1080x1920 -gpu host -no-audio @${avdName}`);
  63. // exec.execSync(`./scripts/waitForAndroidEmulator.sh`);
  64. // }
  65. // function killEmulators() {
  66. // exec.execSync(`adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done`);
  67. // }