-
Notifications
You must be signed in to change notification settings - Fork 82
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
Expect to jest transformer #39
Conversation
Thank you, @skovhus :) How can I try this out? I'm not familiar with how to run a code mod. Is there a doc somewhere? |
Hi @mjackson. I'll update you when the codemod is ready. But this repo has a little CLI that should make it fairly easy to run on an existing codebase. It wraps jscodeshift. See https://github.com/skovhus/jest-codemods#usage-cli But I might try the codemod out on some of your repos with expect. ; ) |
16f3779
to
032ef66
Compare
@mjackson for projects like React History and React Router it seems that you guys are using Expect+Karma+Mocha to execute your tests in Chrome or other browsers. As Jest is executed in node only, these projects might not be good candidates for testing this codemod. Unless if you are interested in switching to a node only test environment? Let me know what you think : ) |
This is fantastic. @skovhus The new version of We may have to provide a single-file build for jest-matchers, that's still to be decided. The idea is to ship this breaking change sometime in mid April. |
Thanks for the input! So essentially two uses cases: for upgrading expect and for upgrading to use Jest as test runner. The output of these two cases can be made compatible if we leave the jest-matchers input in there. So if we import expect from jest-matchers even for users just running on node... that might make sense, as we don't need two codemods or configuration. |
Hmm, here would be my recommendation:
The module |
Two codemods (or configuration) it is. 👍🏻 |
btw. this plugin should help insert requires for the second one: https://github.com/cpojer/js-codemod/tree/master/extensions/imports |
f98db17
to
ce6be63
Compare
e32e2cb
to
409030f
Compare
hi @skovhus I'm excited to use this codemod. We'll be using this exact scenario to move to Jest at my work. Thanks for making it! |
@brantphoto so happy to hear that! : ) I'll let you know when you can try it out. 👍 |
Standalone mode is a bit blocked on jestjs/jest#3360 |
Hey Kenneth! What's the status of this PR? Are you going to merge it? Except for the blocker inside of Jest, is there anything else left that we need to do? |
Nope. Planning to merge it when the standalone mode works for React Router. Everything else should be fine. 😀 |
@cpojer is the plan still to rename Do we want to do that before this codemod goes out? Or should we just change this codemod to migrating from |
We'll publish expect@20 or @21, yes. I'm not sure when yet, but that's the plan. |
@mjackson https://www.npmjs.com/package/expect is being integrated into Jest. This codemod automates the upgrade path. It is extending the work started in cpojer/js-codemod#66
Background: jestjs/jest#1679
/cc @cpojer
Step 1
messages
from all matchers should be removed as some of them actually break Jest (e.g.expect(object).toExist('remove me')
)toInclude
andtoIncludeKeys
that is left but ignored by Jestspy.calls[i].arguments[j] -> spy.mock.calls[i][j]
spy.calls.length -> spy.mock.calls.length
restoreSpies
andresetSpies
isSpy
is missing from Jestimport expect, { createSpy, spyOn, isSpy } from 'expect'
warningexpect
will be used for bothexpect@1
and the new Jest version, we cannot import detect).expect(node.firstChild.innerHTML).not.toMatch(/hello/)
fromreact-media
)expect
are covered (or a warning is logged for unsupported features)Step 2
expect
orjest-matchers
Bugs
console.error
does't havecalls
property when usingjest
spies: