项目作者: skovhus

项目描述 :
Codemods for migrating to Jest https://github.com/facebook/jest 👾
高级语言: TypeScript
项目地址: git://github.com/skovhus/jest-codemods.git
创建时间: 2016-09-17T17:44:42Z
项目社区:https://github.com/skovhus/jest-codemods

开源协议:MIT License

下载



jest-codemods 👾



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,
Tape,
Sinon,
and
Node-Tap
to Jest.

version
downloads
Code Coverage
MIT License
PRs Welcome

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.

Usage (CLI)

To use the interactive CLI run

  1. $ 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

  1. $ npx jest-codemods --help
  2. Usage: npx jest-codemods <path> [options]
  3. Examples: npx jest-codemods src
  4. npx jest-codemods src/**/*.test.js
  5. Options:
  6. -f, --force Bypass Git safety checks and force codemods to run
  7. -d, --dry 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.

Usage (jscodeshift)

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.

  1. $ npm install -g jscodeshift
  2. $ npm install jest-codemods
  3. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/ava.js test-folder
  4. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/chai-assert.js test-folder
  5. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/chai-should.js test-folder
  6. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/expect-js.js test-folder
  7. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/expect.js test-folder
  8. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/jasmine-globals.js test-folder
  9. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/jasmine-this.js test-folder
  10. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/mocha.js test-folder
  11. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/should.js test-folder
  12. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/tape.js test-folder
  13. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/sinon.js test-folder
  14. $ jscodeshift -t node_modules/jest-codemods/dist/transformers/jest-globals-import.js test-folder

Test environment: Jest on Node.js or other

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:

  1. yarn add --dev expect jest-mock
  2. npm install --save-dev expect jest-mock
  3. pnpm install --save-dev expect jest-mock

Transformations

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.

Inspiration

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.

Contributing

To get started, run:

  1. pnpm install

When developing:

  1. pnpm verify # (build/lint/test)
  2. pnpm build
  3. pnpm lint
  4. pnpm test
  5. pnpm test:cov
  6. pnpm test:watch

License

MIT