ทริกเกอร์ 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.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 ...
});