[Question] How to ensure onTestEnd(test, result) completes after the very last test
See original GitHub issueHi,
I am writing my own custom reporter (where test results are logged in a google sheet using the google sheets api) and am running into an issue where the very last test is not reported when using onTestEnd(test, result). Here is my code:
class MyReporter {
onBegin(config, suite) {
console.log(Starting the run with ${suite.allTests().length} tests
);
}
onTestBegin(test) {
console.log(`Starting test ${test.title}`);
}
async onTestEnd(test, result) {
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
// create client instance for auth
const client = await auth.getClient();
// create an instance of google sheets api
const googleSheets = google.sheets({ version: "v4", auth: client });
const spreadsheetId = "ID";
// append the test results to the spreadsheet
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Sheet1!A:B",
valueInputOption: "RAW",
resource: {
values: [[`${result.status}`]],
},
});
console.log(`ending test`);
}
onEnd(result) {
console.log(`Finished the run: ${result.status}`);
}
}
In addition to the google sheet not displaying the final result, the console looks like this: Starting the run with 5 tests Starting test test1 Starting test test2 ending test ending test Starting test test3 Starting test test4 ending test Starting test test5 ending test Finished the run: failed (note: two of the tests are designed to fail, so the run status of “failed” is appropriate)
I believe that when all tests end, playwright stops trying to append the final results to the spreadsheet and thus the reporter does not function properly. All other test results are added as expected. Is there a way to ensure the test runner adds all results before it closes? Thanks!
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (3 by maintainers)
@pavelfeldman well, our request was closed with the same workaround. It’s a pity you don’t plan to add this functionality. I just wanted to emphasize there are several requests for this feature.
Closing as per above, please feel free to open a new issue if this does not cover your use case.