Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
jest-codemods
Advanced tools
Codemods that simplify migrating JavaScript and TypeScript test files from AVA, Chai, Expect.js (by Automattic), Expect@1.x (by mjackson), Jasmine, Mocha, proxyquire, Should.js and Tape to Jest.
Codemods are small programs that help you automate changes to your codebase. Think of them as search and replace on steroids.
We made jest-codemods so you can try out Jest on your existing codebase. We strive to make the migration as smooth as possible, but some manual intervention and tweaks to your tests are to be expected.
To use the interactive CLI run
$ npx jest-codemods
If you do not have npx
installed, you can install the jest-codemods
command globally by running npm install -g jest-codemods
.
For more options
$ npx jest-codemods --help
Codemods for migrating test files to Jest.
Usage
$ npx jest-codemods <path> [options]
path Files or directory to transform. Can be a glob like src/**.test.js
Options
--force, -f Bypass Git safety checks and forcibly run codemods
--dry, -d Dry run (no changes are made to files)
To transform all test files in a directory run jest-codemods .
in your terminal.
Notice the console output for errors, manual intervention and tweaks might be required.
To make the process as simple as possible, we recommend the jest-codemods
CLI
that wraps the jscodeshift executable.
But you can also run the transformations directly using jscodeshift
.
$ npm install -g jscodeshift
$ npm install jest-codemods
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/ava.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/chai-assert.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/chai-should.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/expect-js.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/expect.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/jasmine-globals.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/jasmine-this.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/mocha.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/should.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/tape.js test-folder
If you're using Jest as your test runner and executing tests on Node.js, you'll want to use
the default option when prompted. In this case, jest-codemods
assumes that global values
such as expect
and jest
are provided and will not require()
them explicitly.
If, however, you are using a different test runner or executing Jest tests in a browser,
you may need to choose the option with explicit require()
calls.
In the second case, after running jest-codemods
, you might need to install a few dependencies:
yarn add --dev expect jest-mock
npm install --save-dev expect jest-mock
If possible import
/ require
statements determine if any transformation are carried out.
The original code quoting style is preserved.
Warnings are made if packages are used that are incompatible with Jest.
Thanks to avajs/ava-codemods for inspiration and original CLI setup.
The Mocha and Chai assert support began its life at paularmstrong/mocha-to-jest-codemod.
Chai Should/Expect came from AlexJuarez/chai-to-jasmine.
To get started, run:
yarn
When developing:
yarn run check # (runs lint and unit test)
yarn run lint
yarn run test
yarn run test:cov
yarn run test:watch
MIT
FAQs
Codemods for migrating test files to Jest
The npm package jest-codemods receives a total of 4,179 weekly downloads. As such, jest-codemods popularity was classified as popular.
We found that jest-codemods demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.