آزمایشگاه آزمایش Firebase را با توابع ابری گسترش دهید


یک تابع را در تکمیل TestMatrix راه اندازی کنید

یک تابع جدید ایجاد کنید که وقتی یک TestMatrix با رویداد handler 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 ...
});