Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Jest for testing #51

Closed
rkalis opened this issue Jan 14, 2020 · 1 comment
Closed

Use Jest for testing #51

rkalis opened this issue Jan 14, 2020 · 1 comment
Labels
refactor Internal refactoring
Milestone

Comments

@rkalis
Copy link
Member

rkalis commented Jan 14, 2020

After the call last week I decided to see if I could get Jest up and running.

@rkalis
Copy link
Member Author

rkalis commented Jan 14, 2020

I was able to set up Jest for testing, replacing mocha+chai+nyc. The process was pretty straightforward:

  1. Uninstall Mocha + Chai + nyc.
  2. Install Jest + ts-jest.
  3. Consolidate mocha.opts + .nycrc into jest.config.js and jest.setup.js.
  4. Add env.jest = true to .erclintrc.js.
  5. Update test files to use Jest matchers instead of Chai matchers/assertions.

Then there was one gotcha when using Jest with Bitbox:

  1. Bitbox relies on Buffer instanceof Uint8Array which is expected behaviour. But this breaks with Jest (Jest breaks Buffer instanceof Uint8Array jestjs/jest#4422). The IPFS guys created a custom environment that fixes this (jest-environment-aegir). This code is outdated though, so I updated the code and added it to my own project (jest/custom-environment.js). If you're using Jest with any project that depends on Bitbox, this is a must.

And some optional extra steps I took:

  1. I added extra reporters for cleaner test output.
  2. To make better use of Jest's concurrency I split up some test files into multiple files.

@rkalis rkalis closed this as completed Jan 14, 2020
@rkalis rkalis added this to the v0.3.1 milestone Jan 14, 2020
@rkalis rkalis added the refactor Internal refactoring label Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Internal refactoring
Projects
None yet
Development

No branches or pull requests

1 participant