Skip to content

Team city reporter #882

Description

@bondarewicz

Description

I wonder if anyone tried to use team city reporter for jest?
I'm looking at jest-teamcity-reporter and following guide:

  1. npm install --save-dev jest-teamcity-reporter
  2. package.json
"jest": {
    "testResultsProcessor": "node_modules/jest-teamcity-reporter"
}

and following modification to scripts section:

"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "ci": "react-scripts test --env=jsdom --teamcity"
  },

then run CI=true npm run ci

Expected behavior

Output of team city reporter

Actual behavior

Tests are run with standard reporter and following message have been reported:

react-scripts test --env=jsdom --teamcity
Unrecognized options: teamcity

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected):
    └── react-scripts@0.6.1
  2. node -v:
    v5.1.0
  3. npm -v:
    3.8.1

Activity

  1. wdhorton commented on Oct 10, 2016

    @wdhorton
    Contributor

    Because the react-scripts package is the one actually calling jest, it has its own jest config and doesn't get the config that you put in your package.json:

    "jest": {
        "testResultsProcessor": "node_modules/jest-teamcity-reporter"
    }
    

    ^^ That part doesn't get passed on to react-scripts. I'm not sure there's a way to make this work without ejecting.

  2. bondarewicz commented on Oct 11, 2016

    @bondarewicz
    Author

    Any recommendations to allow passing reporter config into react-scripts ?
    I could not find anything related on roadmap, shall this be considered?

  3. brentatkins commented on Oct 11, 2016

    @brentatkins

    +1 for this.

    I've just run into the exact same problem. Tried messing about with the createJestConfig file in react-scripts, but that executes jest in its own note_modules folder and isn't aware of any dependencies at the project root.

    I'd rather not have to eject the app, but I don't see any other choice.

  4. thien-do commented on Oct 14, 2016

    @thien-do
    Contributor

    Hey guys, have you think about creating a fork version of react-scripts for this use case? It is documented here #779

    (It is not actually a finished document, as there are many tricks to make it works for now, but it do works anyway)

  5. federicobarera commented on Mar 16, 2017

    @federicobarera

    I just had a go and it worked fine.
    navigate to the project root and:

    1. npm install jest

    2. npm install jest-teamcity-reporter

    3. added:
      "jest": { "testResultsProcessor": "jest-teamcity-reporter" }

    4. created a npm script:
      "scripts": { "ci": "jest" }

    Then, please read from their npm page:

    The reporter is only active when the environment variable TEAMCITY_VERSION is present

    Therefore

    SET TEAMCITY_VERSION=1
    npm run ci

    Result:

    r2@0.1.0 ci C:\Users\Federico\Work\Samples\r2
    jest

    PASS src\App.test.js
    √ renders without crashing (4ms)

    Test Suites: 1 passed, 1 total
    Tests: 1 passed, 1 total
    Snapshots: 0 total
    Time: 1.462s
    Ran all test suites.
    ##teamcity[testSuiteStarted name='src/App.test.js']
    ##teamcity[testStarted name='renders without crashing']
    ##teamcity[testFinished name='renders without crashing' duration='4']
    ##teamcity[testSuiteFinished name='src/App.test.js' duration='802']`

  6. mikebridge commented on Apr 7, 2017

    @mikebridge

    When I added jest.testResultsConfigurator directly to my package.json file it interfered with my test compilation, so I removed it and added a parameter to the test-runner script instead:

    "scripts": {
        "test:teamcity": "react-scripts test --env=jsdom --testResultsProcessor=jest-teamcity-reporter"
    }

    Or the create-react-app-typescript equivalent:

    "scripts": {
        "test:teamcity": "react-scripts-ts test --env=jsdom --testResultsProcessor=jest-teamcity-reporter"
    }
  7. bondarewicz commented on Apr 10, 2017

    @bondarewicz
    Author

    @mikebridge would you mind sharing your setup steps?

  8. mikebridge commented on Apr 10, 2017

    @mikebridge

    @bondarewicz When I was debugging it, the only thing I did apart from adding that script immediately after creating the app was to set the environment variable "CI" on the teamcity agent. That works for me both with TypeScript and JavaScript.

  9. gaearon commented on May 16, 2017

    @gaearon
    Contributor

    This is configurable in the next version.
    #1830

  10. added this to the milestone on May 16, 2017
  11. gaearon commented on May 16, 2017

    @gaearon
    Contributor

    Please help beta test the new version that includes this change!
    #2172

  12. brentatkins commented on May 16, 2017

    @brentatkins

    I don't think this issue is closed by #1830

    Outputting Jest results to TeamCity requires overriding the testResultsProcessor config. PR #1830 only deals with jest configuration around coverage, and does not include testResultsProcessor

    I managed to getting it working using the solution listed by @mikebridge

  13. gaearon commented on May 16, 2017

    @gaearon
    Contributor

    Ah good point, sorry. Missed that.
    I do think command line option is better for this because you don't want it locally anyway.

  14. 6 remaining items

  15. gaearon commented on Jun 6, 2017

    @gaearon
    Contributor

    Tagging as needing contributions. Need to look into why this broke.

  16. modified the milestones: 1.0.x, 1.0.0 on Jun 6, 2017
  17. dominicscimeca commented on Jun 6, 2017

    @dominicscimeca

    @gaearon Actually I am looking into just submitting a pull request. So no worries there. Thank you for all your hard work. And the request would be to have the package json option work.
    "jest": { "testResultsProcessor": "jest-teamcity-reporter" }
    Not to fix commandline. This would build on the work from #1830.
    Seems better. Is that agreed?

  18. gaearon commented on Jun 7, 2017

    @gaearon
    Contributor

    The one part I'm confused about: wouldn't that break local watcher? Since I'd expect that "processor" to kick in for local npm test as well.

    If it would break the local watcher, the CLI solution seems preferable. If not, I'm cool with making it configurable in the Jest object.

  19. federicobarera commented on Jun 7, 2017

    @federicobarera

    Guys this is not broken...

    The configuration :

    "jest": { "testResultsProcessor": "jest-teamcity-reporter" }

    already works.
    Just make sure you have the following env:

    env.CI = true env.TEAMCITY_VERSION = 1

  20. gaearon commented on Jun 7, 2017

    @gaearon
    Contributor

    In either case, we need to figure out if passing CLI arguments broke. It's pretty important for us to keep it working.

  21. mikebridge commented on Jun 7, 2017

    @mikebridge

    @dominicscimeca Now that github is back up I can see that the command-line solution still works ok for me after the upgrade---my problem was elsewhere. I had configured options under jest which were no longer permitted.

  22. dominicscimeca commented on Jun 7, 2017

    @dominicscimeca

    @federicobarera The reason yours works is because you are calling jest directly
    "scripts": { "ci": "jest" }
    thus skipping react-scripts entirely. But then of course loosing the benefits of react-scripts. So this is an issue with react-scripts. If you just want to use jest directly of course it will work.

    @gaearon this is a very good point about locally using the package json. Maybe CLI is the best way.

    @mikebridge I will check to see what versions I am using and maybe upgrading will resolve the issue.

  23. dominicscimeca commented on Jun 7, 2017

    @dominicscimeca

    @gaearon @mikebridge I really have to apologize. The CLI works completely fine. I was just on an old version of react-scripts.

  24. denistsoi commented on Jun 27, 2017

    @denistsoi

    think this should be closed @gaearon - @dominicscimeca reported that it seems to be running fine

  25. locked and limited conversation to collaborators on Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions