Test Lab triggers (1st gen)
Stay organized with collections
Save and categorize content based on your preferences.
Trigger a function on TestMatrix completion
Create a new function that triggers when a TestMatrix completes with the event handler
functions.testLab.testMatrix().onComplete():
exports.sendEmailNotification=functions.testLab.testMatrix().onComplete((testMatrix)=>{
//...
});
Handle test states and outcomes
Each execution of your function is passed a TestMatrix
which includes the final state of the matrix and details to help understand problems.
exports.handleTestMatrixCompletion=functions.testLab.testMatrix().onComplete(testMatrix=>{
constmatrixId=testMatrix.testMatrixId;
switch(testMatrix.state){
case'FINISHED':
console.log(`TestMatrix${matrixId}finishedwithoutcome:${testMatrix.outcomeSummary}`);
break;
case'INVALID':
console.log(`TestMatrix${matrixId}wasmarkedasinvalid:${testMatrix.invalidMatrixDetails}`);
break;
default:
console.log(`TestMatrix${matrixId}completedwithstate${testMatrix.state}`);
}
returnnull;
});
Access client details
Test matrices may be created from different sources or workflows. It is therefore often desirable to
create functions that perform different actions based on the source or other important context of
the test. To help with this, gcloud allows you to pass arbitrary information when starting a test
that can be accessed later in your function. For example:
gcloud beta firebase test android run \
--app=path/to/app.apk \
--client-details testType=pr,link=https://path/to/pull-request
Example function:
exports.notifyOnPullRequestFailure=functions.testLab.testMatrix().onComplete(testMatrix=>{
if(testMatrix.clientInfo.details['testType']!='pr'){
//Notapullrequest
returnnull;
}
if(testMatrix.state=='FINISHED' && testMatrix.outcomeSummary=='SUCCESS'){
//Nofailure
returnnull;
}
constlink=testMatrix.clientInfo.details['link'];
letmessage=`TestLabvalidationforpullrequest${link}failed.`;
if(!!testMatrix.resultStorage.resultsUrl){
message+=`Testresultsavailableat${testMatrix.resultStorage.resultsUrl}.`;
}
//Sendnotificationhere...
});