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