ทริกเกอร์ Firebase Test Lab


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