itereshchenkov / jest-teamcity

Jest Teamcity Reporter
MIT License
31 stars 13 forks source link

Suggestion: Option for creating overall suite #30

Open poochy442 opened 2 weeks ago

poochy442 commented 2 weeks ago

I work on an Angular app and just recently converted it from jasmine + karma to Jest. I added this package to help report the test to our TeamCity server and it is working great!

However, we are in a mono repo with multiple different projects, some in TS/JS, some in C#, so we would like to be able to separate these tests from tests of other projects - currently, our TeamCity looks something like this:

Name Other info...
WebApi Tests ...
Playwright Tests ...
\<38 suites for UI tests...> ...

If possible, we would love an option that would turn this into:

Name Other info...
WebApi Tests ...
Playwright Tests ...
UI Tests ...

Where the UI Tests would contain the 38 suites. I would go for path-based sorting as explained below, but any solution that would allow me to group the tests is what I am asking for.

Path-based sorting Suite: name given in config Namespace/package: path[0..-1].Join('.') Class: path[-1] Test: as is

poochy442 commented 2 weeks ago

I wanted to see how hard it was, and I ended up making a whole solution - I can't push branches to this repo, though, so either hit me up and I'll make a PR, or feel free to use the code below. Should you not respond, I might make a fork after a while and do it myself, but I'd prefer to improve on what's already here 😄

formatReport(testResults, cwd, flowId) {
    const totalSuite = process.env.TEAMCITY_TOTAL_SUITE;
    const suites = this.collectSuites(testResults, cwd);

    if(totalSuite) {
      this.log(`##teamcity[testSuiteStarted name='${this.escape(totalSuite)}' flowId='${flowId}']`);
    }

    this.printTestLog(suites, flowId);

    if(totalSuite) {
      this.log(`##teamcity[testSuiteFinished name='${this.escape(totalSuite)}' flowId='${flowId}']`);
    }
  }
itereshchenkov commented 1 week ago

Hey, thanks a lot for the contribution. I'll publish a new version with your suggestion today.

Just one note, TEAMCITY_TOTAL_SUITE will be called as PROJECT_NAME. I think this is a more suitable name according to your description

itereshchenkov commented 1 week ago

New version 1.12 was published. Could you pls check if it satisfies your needs?

poochy442 commented 1 week ago

Hey, thanks for the quick response! Because of a kind of slow review, I just managed to get this new version in the refactor PR 😄

The fix works great for identifying the tests, they now show up as:

Name Other info...
WebApi Tests ...
Playwright Tests ...
UI Tests: \<path-to-test>: \<test-name> ...

This satisfies my use case, so I get it if you resolve it here - however, there are still 38 of them. Having written our Playwright reporter (there was none compatible), I'm pretty sure fixing that is going to involve providing the information from my original comment (Suite, Namespace, Class, Test) instead of adding more suites. As this is a more comprehensive rewrite, again, I would understand if you resolve it here.