Git Product home page Git Product logo

jest-codemods's Introduction

jest-codemods

Codemods that simplify migrating JavaScript test files from Mocha, Tape and AVA to Jest.

Build Status version Tweet

Codemods are small programs that help you automate changes to your codebase. Think of them as search and replace on steroids. They are executed by the Facebook jscodeshift tool.

This tool is made for trying out Jest on your existing test files. We strive to make the migration as smooth as possible, but some manual intervention and tweaks to your tests are to be expected.

Install

$ npm install -g jest-codemods

This installs the runner as jest-codemods.

Usage (CLI)

To use the interactive CLI run

$ jest-codemods

If you are using Flow types

$ jest-codemods --parser flow

For more options

$ jest-codemods --help

	Codemods for migrating test files to Jest.

	Usage
	  $ 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)
	  --parser		The parser to use for parsing your source files (babel | babylon | flow)  [babel]

To transform all test files in a directory run jest-codemods test-folder in your terminal.

Notice the console output for errors, manual intervention and tweaks are to be expected.

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.

$ npm install -g jscodeshift
$ npm install jest-codemods
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/tape.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/ava.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/mocha.js test-folder
$ jscodeshift -t node_modules/jest-codemods/dist/transformers/chai-assert.js test-folder

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.

Usage of proxyquire is replaced with Jest mocks.

Warnings for unsupported features

Warnings for unsupported AVA features:

  • t.skip
  • t.plan

Warnings for unsupported Tape features:

  • t.timeoutAfter
  • t.deepLooseEqual
  • t.looseEqual
  • t.looseEquals
  • t.notDeepLooseEqual
  • t.notLooseEqual
  • t.notLooseEquals
  • t.skip
  • t.plan
  • test.createStream
  • test.onFinish

Inspiration

Thanks to avajs/ava-codemods for inspiration and CLI setup.

The Mocha and Chai support began its life at paularmstrong/mocha-to-jest-codemod

Contributing

To get started, run:

npm install

When developing:

npm run check  # (runs lint and unit test)
npm run lint
npm run test
npm run test:cov
npm run test:watch

License

MIT

jest-codemods's People

Contributors

augustinlf avatar paularmstrong avatar sapegin avatar skovhus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.