https://github.com/wonderflow-bv/to-ava
Convert Jest tests into Ava tests
https://github.com/wonderflow-bv/to-ava
ava codemod jest
Last synced: 12 months ago
JSON representation
Convert Jest tests into Ava tests
- Host: GitHub
- URL: https://github.com/wonderflow-bv/to-ava
- Owner: wonderflow-bv
- Created: 2019-08-04T20:35:17.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T06:16:12.000Z (over 3 years ago)
- Last Synced: 2025-06-06T16:11:26.267Z (about 1 year ago)
- Topics: ava, codemod, jest
- Language: JavaScript
- Size: 484 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# to-ava
Codemod to convert tests written in jest to ava.
Check `fixtures/` folder to see some example.
## Usage
### Install
`npm i -g to-ava`
### Run it on a Javascript file
`to-ava ./jest.test.js`
### Run it on a Typescript file
`to-ava -p=ts ./jest.test.ts`
### Run it on a folder
`to-ava -p=ts ./tests`
### Notes
It excludes files that are not test files. A file is supposed to contain tests if its name includes either `test.` either `spec.`
## Support
### Supported Assertions
- [X] `.toEqual`
- [X] `.toBe`
- [X] `.toBeNull`
- [X] `.toBeFalsy`
- [X] `.toBeTruthy`
- [X] `.toMatchSnapshot`
- [X] `.toBeDefined`
- [X] `.toBeUndefined`
- [X] `.toBeInstanceOf`
- [X] `.toBeGreaterThan`
- [X] `.toBeGreaterThanOrEqual`
- [X] `.toBeLessThan`
- [X] `.toBeLessThanOrEqual`
- [X] `.toHaveLength`
- [X] `.toHaveProperty`
### Other things supported
- [X] `test.each()`
- [X] trasnformation of test hooks (`before()`, `beforeEach()`, `after()`, `afterAll()`)
### Assertions not supported
All the other assertions are not supported. Including all the assertions used in combination with `.not` - for example `.not.toBeDefined()`
Those assertions will be still transformed, however not into an ava assertion, but as a comment with the "TODO: " symbol. Thanks for the "TODO: " symbol, it will be possible to find all the assertions not transformed, and fix them manually.
For example
```js
expect(res).toContain('0')
// will be transformed into
// TODO: expect(res).toContain('0');
```
### Other things not supported
- [ ] nested `describe()` - require manual rewriting of jest tests in order to remove nested `describe()`
- [ ] skipped tests `describe.skip()`, `it.skip()`
## Test
`npm t`
## TODO
- [X] add support for beforeEach, beforeAll, afterEach, afterAll
- [ ] refactor: split the transformer into multiple functions, with clear names
- [ ] add support for more jest assertion. The list follows:
- [ ] `.not.toBeDefined`
- [ ] `.not.toBeNull`
- [ ] `.not.toContain`
- [ ] `.not.toEqual`
- [ ] add support for nested describes
## Resources
- [Ava to Jest transformers](https://github.com/skovhus/jest-codemods/blob/master/src/transformers/ava.js)
- [AST Explorer](https://astexplorer.net/)