ทริกเกอร์ฟังก์ชันเมื่อ 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 ...
});