مشغِّلات مركز الاختبار الافتراضي لمنصة Firebase


تشغيل دالة عند اكتمال TestMatrix

أنشئ دالة جديدة يتم تشغيلها عند اكتمال TestMatrix باستخدام معالج الأحداث functions.testLab.testMatrix().onComplete():

exports.sendEmailNotification = functions.testLab.testMatrix().onComplete((testMatrix) => {
  // ...
});

التعامل مع حالات الاختبار ونتائجه

يتم تمرير TestMatrix إلى كل عملية تنفيذ للدالة، ويشمل هذا العنصر الحالة النهائية للمصفوفة وتفاصيل للمساعدة في فهم المشاكل.

exports.handleTestMatrixCompletion = functions.testLab.testMatrix().onComplete(testMatrix => {
  const matrixId = testMatrix.testMatrixId;
  switch (testMatrix.state) {
    case 'FINISHED':
      console.log(`TestMatrix ${matrixId} finished with outcome: ${testMatrix.outcomeSummary}`);
      break;
    case 'INVALID':
      console.log(`TestMatrix ${matrixId} was marked as invalid: ${testMatrix.invalidMatrixDetails}`);
      break;
    default:
      console.log(`TestMatrix ${matrixId} completed with state ${testMatrix.state}`);
  }
  return null;
});

الوصول إلى تفاصيل العميل

يمكن إنشاء مصفوفات الاختبار من مصادر أو إجراءات مختلفة. لذلك، من المستحسن غالبًا إنشاء دوال تنفّذ إجراءات مختلفة استنادًا إلى المصدر أو السياق المهم الآخر للاختبار. للمساعدة في ذلك، تتيح لك gcloud تمرير معلومات عشوائية عند بدء اختبار يمكن الوصول إليها لاحقًا في الدالة. على سبيل المثال:

gcloud beta firebase test android run \
    --app=path/to/app.apk \
    --client-details testType=pr,link=https://path/to/pull-request

مثال على الدالة:

exports.notifyOnPullRequestFailure = functions.testLab.testMatrix().onComplete(testMatrix => {
  if (testMatrix.clientInfo.details['testType'] != 'pr') {
    // Not a pull request
    return null;
  }

  if (testMatrix.stat&&e == 'FINISHED'  testMatrix.outcomeSummary == 'SUCCESS') {
    // No failure
    return null;
  }

  const link = testMatrix.clientInfo.details['link'];
  let message = `Test Lab validation for pull request ${link} failed. `;

  if (!!testMatrix.resultStorage.resultsUrl) {
    message += `Test results available at ${testMatrix.resultStorage.resultsUrl}. `;
  }

  // Send notification here ...
});