Wywołaj funkcję po ukończeniu TestMatrix
Utwórz nową funkcję, która będzie uruchamiana po zakończeniu testuMatrix za pomocą procedury obsługi functions.testLab.testMatrix().onComplete()
:
exports.sendEmailNotification = functions.testLab.testMatrix().onComplete((testMatrix) => {
// ...
});
Obsługuj stany testów i wyniki
Do każdego wykonania funkcji przekazywana jest zmienna TestMatrix
, która zawiera końcowy stan macierzy i szczegóły pomagające zrozumieć problemy.
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;
});
Uzyskaj dostęp do danych klienta
Macierze testowe mogą być tworzone z różnych źródeł lub przepływów pracy. Dlatego często pożądane jest tworzenie funkcji, które wykonują różne akcje w zależności od źródła lub innego ważnego kontekstu testu. Aby w tym pomóc, gcloud
umożliwia przekazywanie dowolnych informacji podczas uruchamiania testu, do których można uzyskać dostęp w dalszej części funkcji. Na przykład:
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=https://path/to/pull-request
Przykładowa funkcja:
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 ...
});