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

Add docs about using Hardhat with jest #595

Open
adrianmcli opened this issue May 21, 2020 · 12 comments
Open

Add docs about using Hardhat with jest #595

adrianmcli opened this issue May 21, 2020 · 12 comments
Labels
status:ready This issue is ready to be worked on type:docs Documentation-related issue

Comments

@adrianmcli
Copy link
Contributor

Buidler is a great framework, but it lacks official support or documentation for Jest. I've talked about this with @alcuadrado before and he agrees that maybe a guide would be helpful, so I created this issue to track this.

Note that Jest is by far the most popular framework, but most of the crypto world is not aware. My theory is because most crypto people are from the backend world. And Jest is largely a frontend-driven phenomenon:

Screen Shot 2020-05-21 at 11 05 26 AM

Source: https://npmcharts.com/compare/mocha,jest,chai

I will try to take some time to experiment with different setups and report back here.

@alcuadrado
Copy link
Member

Oh, wow! I had no idea that jest was THAT popular.

Thanks for creating this issue and taking the time to analyze how to use it with Buidler.

@0xNetizen
Copy link

Hi @adrianmcli, any updates for us?

@adrianmcli
Copy link
Contributor Author

@BnWng I've been swamped lately since I started at UMA. That being said, I have a side project idea that I might try next weekend and I'll be using Jest w/ Buidler. Hopefully I'll have something to show for it by then!

@adrianmcli
Copy link
Contributor Author

@BnWng I made some Jest matchers for Waffle to test: TrueFiEng/Waffle#321

Would be cool to get your input. I have a feeling it still needs a lot of work though. I'm curious about how people use Buidler with Jest. That could help inform how to write a guide for Buidler.

@0xNetizen
Copy link

Looks great @adrianmcli . However, I'm now using mocha and chai for my current project. But it looks like you've recreated all the crucial functionality with the chai matchers (which was why I switched away from Jest). I'll make sure to try it out with Jest when I get around to it. Thanks!

@rryter
Copy link

rryter commented Nov 1, 2020

I have started building a Jest plugin for Hardhat:
https://github.com/rryter/hardhat-jest-plugin

The most basic use-case does work, meaning you can run hardhat test:jest and the tests run once. Obviously I want to support the watch mode too, without loosing the stack traces and so on. I'm currently looking into that.

If anyone wants to help, it's greatly appreciated.

@fvictorio fvictorio added the type:docs Documentation-related issue label Jun 10, 2021
@fvictorio fvictorio added priority:medium status:ready This issue is ready to be worked on labels Dec 30, 2022
@fvictorio fvictorio changed the title Jest support and guide Add docs about using Hardhat with jest Dec 30, 2022
@yannickrocks
Copy link

Hi there

I would like to reopen this issue (sorry)
Is there a possibly that hardhat can be using the JEST testing suite?

@arianXdev
Copy link
Contributor

Hi there

I would like to reopen this issue (sorry) Is there a possibly that hardhat can be using the JEST testing suite?

Hi @yannickrocks

Yeah, it's definitely possible, If you want to use Jest in your Hardhat projects, I've developed a Hardhat plugin called hardhat-jest that basically lets you run your Jest tests seamlessly only by running the command npx hardhat jest and I also have written an article on Medium about it "How to use Jest in Hardhat Projects" that you can check it out for more details if you want, providing an in-depth guide to use Jest in your projects,

Hope that it will help you,

and I also appreciate your feedback, contributions, and help if you'd like to.

Thanks.

@yannickrocks
Copy link

Hi there

I would like to reopen this issue (sorry) Is there a possibly that hardhat can be using the JEST testing suite?

Hi @yannickrocks

Yeah, it's definitely possible, If you want to use Jest in your Hardhat projects, I've developed a Hardhat plugin called hardhat-jest that basically lets you run your Jest tests seamlessly only by running the command npx hardhat jest and I also have written an article on Medium about it "How to use Jest in Hardhat Projects" that you can check it out for more details if you want, providing an in-depth guide to use Jest in your projects,

Hope that it will help you,

and I also appreciate your feedback, contributions, and help if you'd like to.

Thanks.

Hey Ryan

Will give this a go. Thank you!

@yannickrocks
Copy link

@RyanHosseini Thank you for the package recommendation. Works like a charm 👍

I have a question though. Does Hardhat coverage only show coverage on the solidity files?
If so, does that mean I would still need to run jest --coverage just to see the coverage on other tests files?

@arianXdev
Copy link
Contributor

@RyanHosseini Thank you for the package recommendation. Works like a charm +1

I have a question though. Does Hardhat coverage only show coverage on the solidity files? If so, does that mean I would still need to run jest --coverage just to see the coverage on other tests files?

@yannickrocks I'm so glad it was helpful for you! 😃 Don't forget to star the repo as well 😇

Unfortunately, Hardhat coverage uses solidity-coverage plugin under the hood which is only compatible with Mocha yet, So it seems like it's a little bit challenging to see the coverage in Jest test files.

Pleaes let me know if there's any other thing that I can help you.

@yannickrocks
Copy link

@RyanHosseini Thank you for the package recommendation. Works like a charm +1
I have a question though. Does Hardhat coverage only show coverage on the solidity files? If so, does that mean I would still need to run jest --coverage just to see the coverage on other tests files?

@yannickrocks I'm so glad it was helpful for you! 😃 Don't forget to star the repo as well 😇

Unfortunately, Hardhat coverage uses solidity-coverage plugin under the hood which is only compatible with Mocha yet, So it seems like it's a little bit challenging to see the coverage in Jest test files.

Pleaes let me know if there's any other thing that I can help you.

@RyanHosseini Thanks and will do 😄

Do you know how many workers are used in the hardhat jest package and how we can set them?

Issue I was having were tests were passing locally but failing on a github pipeline. Seems like the deploy scripts would struggle to initialise contracts and would throw a VM Exception error.

Is it recommended to use the snapshot functionality for the tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready This issue is ready to be worked on type:docs Documentation-related issue
Projects
Status: No status
Development

No branches or pull requests

7 participants