karma-teamcity-reporter icon indicating copy to clipboard operation
karma-teamcity-reporter copied to clipboard

Test names formatting for BDD

Open kottenator opened this issue 7 years ago • 2 comments

Hi!

First of all, Karma is awesome! You're doing great job! ;)

But I have a specific problem.

I use Jasmine JS test framework. For example, one of my tests:

describe("QueryDict utility", () => {
  it("should parse '?a=1&b=2' into {a: [1], b: [2]}", () => {
    expect(new QueryDict('a=1&b=2').toObject()).toEqual({a: ['1'], b: ['2']});
  });
});

It will provide the following information for the reporter:

  • result.suite == ["QueryDict utility"]
  • result.description == "should parse '?a=1&b=2' into {a: [1], b: [2]}"

If I use karma-teamcity-reporter, it generates the following:

##teamcity[testSuiteStarted name='QueryDict utility.Firefox 52.0.0 (Linux 0.0.0)']
##teamcity[testStarted name='should parse |'?a=1&b=2|' into {a: |[1|], b: |[2|]}']
##teamcity[testFinished name='should parse |'?a=1&b=2|' into {a: |[1|], b: |[2|]}' duration='11']
##teamcity[testSuiteFinished name='QueryDict utility.Firefox 52.0.0 (Linux 0.0.0)']

This has several problems:

image

Suite/class/test names

I don't think that suiteName + '.' + browserName is the best decision for the suite name in TC (e.g. QueryDict utility.Firefox 52.0.0 (Linux 0.0.0)).

In my example, QueryDict utility is more like a class name.

One JS test file can have more than one describe() and each describe() can contain multiple it(). It looks similar to:

  • JS test file:
    • describe() ↔ test class
      • it() ↔ test class method

And suite name is something above the test classes. Suite groups test classes. Maybe it's good to have the JS test filename as the suite name but I'm not sure that it's available in Karma reporter. So it may be e.g. the browser name.

What I suggest

  • TC suite name: browser.name (e.g. Firefox 52.0.0 (Linux 0.0.0))
  • TC class name: require('snake-case')(result.suite.join(' ')) (e.g. query_dict_utility)
  • TC test name: result.suite.join(' ') + ' ' + result.description (e.g. QueryDict utility should parse '?a=1&b=2' into {a: [1], b: [2]})

So it'll look like this in TC:

image

TeamCity wrongly parses :\u0020 in test names

As you can see on my first screenshot, my test name is awfully parsed and displayed in TC tests report:

  • TC test name: [2]}
  • TC class name: n/a
  • TC suite name: QueryDict utility.Firefox 52.0.0 (Linux 0.0.0): should parse '?a=1&b=2' into {a: [1], b

That's not your fault:

  • TC finds the last :\u0020 entry in the test name
  • everything before it considered as the suite name
  • ... despite that the suite name is already set and shouldn't be parsed at all.

There's a bug in TC YouTrack. However, there's a workaround that may be implemented in karma-teamcity-reporter: you can replace all :\u0020 with :\u00a0 - then TeamCity will skip it.

What I suggest

Replace all :\u0020 with :\u00a0 in the test name.

Custom names formatting

Compared to karma-junit-reporter, you don't provide any way to customize suite/class/test names.

What I suggest

Please, provide a way to customize suite/class/test names e.g. similar to how it's done in karma-junit-reporter:

config.set({
  // ...
  teamcityReporter: {
    suiteNameFormatter(browser, result) {
      // ...
    },
    testNameFormatter(browser, result) {
      // ...
    }
  }
});

kottenator avatar May 24 '17 18:05 kottenator

Suite/class/test names +1, i`d love to group all unit tests in one suite and all describes as classes)

akaguny avatar Sep 21 '17 22:09 akaguny

ping developers? :)

kottenator avatar Apr 06 '18 18:04 kottenator