简体   繁体   中英

Tests slow when using jest with web3 and ganache

I have an end-to-end test using jest that deploys several Ethereum contracts to ganache via web3 and communicates with them.

The test is very slow on jest, taking over a minute when running it directly without jest takes 10 seconds. I created a new clean project that isolates this test, it's the only test in the project.

I followed the jest troubleshooting guide and tried all the performance related tips, like --runInBand , yet they had negligible effect.

Jest runs inside a VM which makes crypto calculations very slow. Since web3 is heavy with crypto calculations, signatures and such, this overhead kills the test.

The solution is adding the following to the jest config file:

"extraGlobals": ["Math"]

For more info, see https://jestjs.io/docs/en/configuration#extraglobals-arraystring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM