I wonder if anyone tried to use team city reporter for jest?
I'm looking at jest-teamcity-reporter and following guide:
npm install --save-dev jest-teamcity-reporterpackage.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
Output of team city reporter
Tests are run with standard reporter and following message have been reported:
react-scripts test --env=jsdom --teamcity
Unrecognized options: teamcity
Run these commands in the project folder and fill in their results:
npm ls react-scripts (if you haven’t ejected):└── [email protected]node -v:v5.1.0npm -v:3.8.1Because 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.
Any recommendations to allow passing reporter config into react-scripts ?
I could not find anything related on roadmap, shall this be considered?
+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.
Hey guys, have you think about creating a fork version of react-scripts for this use case? It is documented here https://github.com/facebookincubator/create-react-app/pull/779
(It is not actually a finished document, as there are many tricks to make it works for now, but it do works anyway)
I just had a go and it worked fine.
navigate to the project root and:
added:
"jest": {
"testResultsProcessor": "jest-teamcity-reporter"
}
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
5.
SET TEAMCITY_VERSION=1
npm run ci
Result:
[email protected] 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.
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"
}
@mikebridge would you mind sharing your setup steps?
@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.
This is configurable in the next version.
https://github.com/facebookincubator/create-react-app/pull/1830
Please help beta test the new version that includes this change!
https://github.com/facebookincubator/create-react-app/issues/2172
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
Ah good point, sorry. Missed that.
I do think command line option is better for this because you don't want it locally anyway.
@gaearon Why is this closed? Should there be another issue to track this? Because @mikebridge's solution does not currently work. And the pull request and new version don't address this either.
I looked through the code and could not even see how @mikebridge's solution would work. maybe in a previous version of react scripts.
@dominicscimeca I just upgraded and it is now broken for me too.
Why is this closed? Should there be another issue to track this? Because @mikebridge's solution does not currently work.
It is closed because nobody reported it was broken 😉
Now that you reported, I am reopening.
I expect the solution in https://github.com/facebookincubator/create-react-app/issues/882#issuecomment-292662719 to work.
If it doesn't, it would be great if you (or somebody else) could look into why it broke.
Thanks!
Tagging as needing contributions. Need to look into why this broke.
@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 https://github.com/facebookincubator/create-react-app/pull/1830.
Seems better. Is that agreed?
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.
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
In either case, we need to figure out if passing CLI arguments broke. It's pretty important for us to keep it working.
@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.
@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.
@gaearon @mikebridge I really have to apologize. The CLI works completely fine. I was just on an old version of react-scripts.
think this should be closed @gaearon - @dominicscimeca reported that it seems to be running fine
Most helpful comment
When I added
jest.testResultsConfiguratordirectly to mypackage.jsonfile it interfered with my test compilation, so I removed it and added a parameter to the test-runner script instead:Or the create-react-app-typescript equivalent: