محرک های آزمایشگاه تست (نسل اول)

فعال کردن یک تابع پس از تکمیل 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.state == '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 ...
});