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