Firebase Test Lab'ı Cloud Functions ile Genişletin


TestMatrix tamamlandığında bir işlevi tetikleyin

Bir TestMatrix, olay işleyicisi functions.testLab.testMatrix().onComplete() ile tamamlandığında tetiklenen yeni bir işlev oluşturun:

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

Test durumlarını ve sonuçlarını ele alın

İşlevinizin her yürütülmesi, matrisin son durumunu ve sorunların anlaşılmasına yardımcı olacak ayrıntıları içeren bir TestMatrix geçirilir.

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;
});

Müşteri ayrıntılarına erişin

Test matrisleri farklı kaynaklardan veya iş akışlarından oluşturulabilir. Bu nedenle, testin kaynağına veya diğer önemli bağlamına göre farklı eylemleri gerçekleştiren işlevler oluşturmak genellikle arzu edilir. Buna yardımcı olmak için gcloud , daha sonra işlevinizde erişilebilecek bir testi başlatırken isteğe bağlı bilgileri aktarmanıza olanak tanır. Örneğin:

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

Örnek fonksiyon:

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 ...
});