Триггеры 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 ...
});