-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests: Try to migrate server and integration tests to Jest #14364
Conversation
Test live: |
b55424e
to
8f157da
Compare
Might it be possible to do this more cautiously by introducing jest alongside mocha and then incrementally migrate? Perhaps we can use a mutually exclusive pattern for test filenames (like 'spec' instead of 'test') We could introduce and discuss some new tests (specs!) that demonstrate use of jest features (such as snapshots), communicate these more broadly and then start the process for migration once the idea has momentum. Codemods might then be used to get us the rest of the way. |
1669c2f
to
3c0d65c
Compare
} ); | ||
|
||
it( 'should return components stats only', done => { | ||
getComponentsUsageStats( ( err, res ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how it was passing before ...
It had empty body in the identical call in the previous test which calls the same function:
expect( res.body ).not.to.be.empty;
f9ec6bd
to
8bba761
Compare
circle.yml
Outdated
@@ -27,8 +27,7 @@ test: | |||
- server/**/*.jsx | |||
- MOCHA_FILE=./test-results-client.xml npm run test-client -- -R mocha-junit-reporter -t $CIRCLE_NODE_TOTAL -i $CIRCLE_NODE_INDEX: | |||
parallel: true | |||
- MOCHA_FILE=./test-results-server.xml npm run test-server -- -R mocha-junit-reporter -t $CIRCLE_NODE_TOTAL -i $CIRCLE_NODE_INDEX: | |||
parallel: true | |||
- npm run test-server:ci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this line tests are executed only on node 0, which isn't what I would expect. This needs to be further investigated.
@markryall thanks for sharing good ideas 👍
I stumbled upon this article https://medium.com/@RubenOostinga/combining-chai-and-jest-matchers-d12d1ffd0303 this week. It helped me to alias Mocha specific lifecycle methods to make them work with Jest. I hope it allows to use Mocha syntax and Jest runner with the client side code, too :)
I don't like the idea of having two different file extensions, because it only makes everything more complicated. I like a lot the rest of suggestion though. It would be nice to be able to run the same tests with Mocha and Jest at the same time, to validate the transition. I'm still not sure if Jest is going to be faster because it initiates testing env for every test suite to ensure they are isolated. It runs tests concurrently, which might make it perform better locally, but it might be no go on Circle CI.
Yes, they are very granular and have interactive mode. So you can migrate everything step by step. |
@gziolo that's awesome - if we can just make existing mocha tests work with jest using this aliasing trick then that certainly makes the transition easier. We'd still have to make the before vs beforeAll change everywhere wouldn't we? That could also probably be handled with some test config. Maybe the same for 'context'. I'd had performance issues with jest when using it a couple of years ago but we had automocking enabled. I think the useMockery approach we already have for mocks is superior (although less succinct) - jest mocks seem needlessly complicated to me. |
test/setup-test-framework.js
Outdated
return Object.assign( chaiMatchers, originalMatchers ); | ||
}; | ||
|
||
// Make sure we can share test helpers between Mocha and Jest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd still have to make the before vs beforeAll change everywhere wouldn't we? That could also probably be handled with some test config. Maybe the same for 'context'.
@markryall this is enough to make Jest work with Mocha helpers. We can add the same for context
:)
Fortunately they disabled automocking last year and introduced several other performance improvements.
There is also a codemod that is able to rename all |
@blowery |
server/jest.config.ci.js
Outdated
module.exports = Object.assign( | ||
{}, | ||
{ | ||
testResultsProcessor: './node_modules/jest-junit-reporter', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was quite easy to integrate a reporter that is going to play nicely with Circle CI 🎉
@gwwar I rebased with master, updated Jest to the latest version and fixed some new issues. Can you review the last 3 commits before this gets merged? :) |
We can wait, it may take a couple of days until they update repository. The patent clause was the only blocker. As far as I know, people are very excited about Jest. |
a80eab1
to
c01624e
Compare
Okey, it is now rebased and updated to use |
0daac6a
to
04a8861
Compare
package.json
Outdated
@@ -234,8 +234,6 @@ | |||
"test-server:ci": "cross-env TEST_REPORT_FILENAME=./test-results-server.xml jest -c=test/server/jest.config.ci.js -w=2", | |||
"test-server:coverage": "npm run -s test-server -- --coverage", | |||
"test-server:watch": "npm run -s test-server -- --watch", | |||
"test-test": "cross-env NODE_ENV=test NODE_PATH=test:client:client/extensions TEST_ROOT=test node test/runner.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yaaaaay
@@ -269,9 +267,6 @@ | |||
"jscodeshift": "0.3.30", | |||
"md5-file": "3.1.0", | |||
"mixedindentlint": "1.2.0", | |||
"mocha": "3.1.0", | |||
"mocha-junit-reporter": "1.12.0", | |||
"mockery": "1.7.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay
04a8861
to
11be7ed
Compare
This PR migrates server and integration tests from Mocha to Jest.
Integration tests
npm run test-integration
npm run test-integration:ci
- version tailored for CircleCInpm run test-integration:watch
- run with watch mode enabled, by default it executes tests only for modified filesI skipped code coverage for integration tests, because it isn't important at all in this context.
Server tests
npm run test-server
npm run test-server:ci
- version tailored for CircleCInpm run test-server:coverage
- run with code coverage enablednpm run test-server:watch
- run with watch mode enabled, by default it executes tests only for modified filesSummary
This also breaks other test runners because I modified the helpers from the/test/
folder to make it work with Jest. Mocha usesbefore
, but Jest wantsbeforeAll
:(I followed this awesome article to make test helpers work with Mocha and Jest at the same time.
Code coverage result for
/server/
folderTODO
mocha-junit-reporter
like reporter on Circle CI