Skip to content

Instantly share code, notes, and snippets.

@fernyb
Created October 17, 2021 18:10
Show Gist options
  • Save fernyb/813ff8764b6dc969f1574df349ae59f9 to your computer and use it in GitHub Desktop.
Save fernyb/813ff8764b6dc969f1574df349ae59f9 to your computer and use it in GitHub Desktop.
Mocha TeamCity Reporter

Report displays correctly in TeamCity. But "testFinished" should be ignored because TeamCity says "testIgnored" should not have "testStarted/testFinished" pairs.

Reference: https://www.jetbrains.com/help/teamcity/service-messages.html#Supported+test+service+messages

##teamcity[testIgnored name='testName' message='ignore comment']

testIgnore tag Indicates that testName is present but was not run (was ignored) by the testing framework. As an exception, the testIgnored message can be reported without the matching testStarted and testFinished messages.

mocha-teamcity-reporter npm package will generate the following when 1 test has a skip test.

##teamcity[testSuiteStarted name='Top Describe' flowId='25695']
##teamcity[testStarted name='Passing Test @pass' captureStandardOutput='true' flowId='25695']
##teamcity[testFinished name='Passing Test @pass' duration='1' flowId='25695']
##teamcity[testStarted name='Failing Test @fail' captureStandardOutput='true' flowId='25695']
##teamcity[testFinished name='Failing Test @fail' duration='2' flowId='25695']
##teamcity[testIgnored name='Skipped Test @skip' message='Skipped Test @skip' flowId='25695']
##teamcity[testFinished name='Skipped Test @skip' flowId='25695']
##teamcity[testSuiteFinished name='Top Describe' duration='6' flowId='25695']

Cypress using mocha-teamcity-reporter will generate the following:

##teamcity[testSuiteStarted name='HelloWorld' flowId='27569']
##teamcity[testStarted name='say hello' captureStandardOutput='true' flowId='27569']
##teamcity[testFinished name='say hello' duration='28' flowId='27569']
##teamcity[testIgnored name='let me skip' message='let me skip' flowId='27569']
##teamcity[testStarted name='let me skip' captureStandardOutput='true' flowId='27569']
##teamcity[testIgnored name='a pending test' message='a pending test' flowId='27569']
##teamcity[testStarted name='a pending test' captureStandardOutput='true' flowId='27569']
##teamcity[testStarted name='Goodbye!' captureStandardOutput='true' flowId='27569']
##teamcity[testFinished name='Goodbye!' duration='27' flowId='27569']
##teamcity[testSuiteFinished name='HelloWorld' duration='60' flowId='27569']

Which is incorrect because it contains "testStarted"/"testFinished" for every "testIgnored" test. This causes TeamCity to report testIgnored a passing test.

After patching mocha-teamcity-reporter to not print "testStarted"/"testFinished" the report looks good in TeamCity as we expect. The patched generated teamcity report:

##teamcity[testSuiteStarted name='HelloWorld' flowId='28312']
##teamcity[testStarted name='say hello' captureStandardOutput='true' flowId='28312']
##teamcity[testFinished name='say hello' duration='28' flowId='28312']
##teamcity[testIgnored name='let me skip' message='let me skip' flowId='28312']
##teamcity[testIgnored name='a pending test' message='a pending test' flowId='28312']
##teamcity[testStarted name='Goodbye!' captureStandardOutput='true' flowId='28312']
##teamcity[testFinished name='Goodbye!' duration='19' flowId='28312']
##teamcity[testSuiteFinished name='HelloWorld' duration='57' flowId='28312']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment