Skip to content
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

Testing: Replace Mocha legacy methods with Jest alternatives #18695

Merged
merged 1 commit into from
Oct 11, 2017

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Oct 10, 2017

Another step to have tests API closer to Jest and therefore more consistent code.

This is an automated refactoring performed with jest-codemods assisted with prettier run. It boils down to the following transformations:

  • before -> beforeAll
  • after -> afterAll
  • context -> describe
  • it -> test
  • use arrow function wherever applicable

Testing

Make sure all existing tests pass:

  • npm run test-client
  • npm run test-integration
  • npm run test-server

Please note that linter fails in a few places, but all of them existed before. I don't plan to tackle those issues as part of this PR.

@gziolo gziolo added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Type] Janitorial labels Oct 10, 2017
@gziolo gziolo self-assigned this Oct 10, 2017
@matticbot
Copy link
Contributor

@gziolo gziolo force-pushed the update/jest-api-codemod branch 2 times, most recently from 4ef7f0a to df82036 Compare October 10, 2017 14:00
@gziolo
Copy link
Member Author

gziolo commented Oct 10, 2017

@skovhus - I see some improvements in how jest-codemods work. I had to fix 1 test manually because it was using test method from sinon. Otherwise everything went perfectly fine with 1 000+ tests. Cheers :)

@skovhus
Copy link

skovhus commented Oct 10, 2017

@gziolo so happy to hear. Please let me know which cases you needed to manual fix. Would be awesome if you could create an issue here https://github.com/skovhus/jest-codemods

When looking at you tests it might makes sense to keep it instead of test. Might want to revisit skovhus/jest-codemods#64 if you feel for it.

@gziolo
Copy link
Member Author

gziolo commented Oct 10, 2017

Please let me know which cases you needed to manual fix. Would be awesome if you could create an issue here https://github.com/skovhus/jest-codemods

@skovhus it was this file: https://github.com/Automattic/wp-calypso/blob/4a6ff2c0d6c509996fe054a4c341f372683b193a/client/components/token-field/test/index.jsx - this link is to the version before I updated it manually. There are 2 root causes:

  • import { test } from 'sinon'; which overrides test from Jest.
  • test from Sinon does some trick which exposes Sinon API inside the test using this. notation, e.g. this.clock.tick( 100 );

If you think it's something you want to fix, I can open an issue or comment on the existing one for Sinon.

When looking at you tests it might makes sense to keep it instead of test. Might want to revisit skovhus/jest-codemods#64 if you feel for it.

It would be nice to have a choice, but honestly speaking, it's closer to the official docs. I'm fine with that as long as it's automated :)

@skovhus
Copy link

skovhus commented Oct 10, 2017

If you think it's something you want to fix, I can open an issue or comment on the existing one for Sinon.

Thanks for explaining. Seems like rather special case... Was it hard to figure out what went wrong?

@gziolo
Copy link
Member Author

gziolo commented Oct 10, 2017

Thanks for explaining. Seems like rather special case... Was it hard to figure out what went wrong?

It was very easy to fix. Cross-commented here: skovhus/jest-codemods#68 (comment).

@skovhus
Copy link

skovhus commented Oct 10, 2017

Thanks for letting me know. : )

@jsnmoon
Copy link
Contributor

jsnmoon commented Oct 10, 2017

Seeing the following integration test failures:

  • devdocs › should return documents
  • devdocs › should return documents with relative paths
  • devdocs › should return the README.md by default
  • devdocs › should not allow viewing files outside the Calypso repo
  • devdocs › should not allow viewing JavaScript files
  • devdocs › components usage stats endpoint › should return stats

Should be pretty easy to replicate these failures by running npm run test-integration.

EDIT: It looks like these tests fail on master too... Fixing this might be outside the scope of this PR.

@gziolo
Copy link
Member Author

gziolo commented Oct 11, 2017

Should be pretty easy to replicate these failures by running npm run test-integration.

EDIT: It looks like these tests fail on master too... Fixing this might be outside the scope of this PR.

It's strange. It works locally for me even after I execute npm run distclean. It also works with the latest master. Can you open an issue with more details?

@gziolo gziolo force-pushed the update/jest-api-codemod branch from df82036 to 53610ba Compare October 11, 2017 06:36
Copy link
Contributor

@samouri samouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing Done:

  • test-client
  • test-server
  • test-integration

Also I scanned through the first 20ish files and they all looked good

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Well done! All tests suites passing here.

@gziolo gziolo merged commit 674f8a0 into master Oct 11, 2017
@gziolo gziolo deleted the update/jest-api-codemod branch October 11, 2017 07:40
@gziolo
Copy link
Member Author

gziolo commented Oct 11, 2017

Thanks for review 💯

@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants