טריגרים של Firebase Test Lab


הפעלת פונקציה בסיום של 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.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 ...
});