Cloud Functions की मदद से 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.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 ...
});