The script automates parts of the migration from our current testing suites to jest. It is based on the code developed by Contactually. The story underlying this code can be found in this blog post.
The script uses jest-codemods. The file to test is from and egghead lesson (the code itself is available on Github).
The script runs in 3 parts, automatically committing the changes in-between:
- It copies the test files .spec.js into the folder test and rename them with the extension test.js
- It applies several transformers from jest-codemods
- It replaces ad-hoc test expressions by jest expressions
The script and the process to run it is still a work in progress. For now
- Copy the script file
mocha-and-sinon-to-jest.js
to the directory where the tests you want to convert are. - Run
node mocha-and-sinon-to-jest.js .
- A new directory
__test__
should be added to the directory with the converted test files in it.