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