question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to ensure onTestEnd(test, result) completes after the very last test

See original GitHub issue

Hi,

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
viraxslotcommented, Jun 6, 2022

@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.

0reactions
pavelfeldmancommented, Jun 3, 2022

Closing as per above, please feel free to open a new issue if this does not cover your use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reporter | Playwright - CukeTest
onTestEnd (test, result) is called when test run has finished. By this time, TestResult is complete and you can use testResult.status, testResult.error and...
Read more >
Is it possible to run code after all tests finish executing in MStest
Yes it is possible. You can use the AssemblyCleanup Attribute for this purpose: Identifies a method that contains code to be used after...
Read more >
Reset Unit Tests - Khan Academy Help Center
Why can't we reset the unit tests/quizzes after messing up? I've been at this for hours and cannot get 100% because it makes...
Read more >
More Assertions
Even though Google Test has a rich set of assertions, they can never be complete, as it's impossible (nor a good idea) to...
Read more >
tests/gtest/googletest/docs/AdvancedGuide.md ... - GitLab Inria
Availability: Linux, Windows, Mac; since version 1.1.0. Predicate Assertions for Better Error Messages. Even though Google Test has a rich set of assertions, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found