Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Introduce mocha + chai and implement some tests with it #225

Closed
wants to merge 1 commit into from

Conversation

gvko
Copy link
Contributor

@gvko gvko commented Apr 23, 2021

No description provided.

@gvko gvko self-assigned this Apr 23, 2021
@gvko gvko marked this pull request as draft April 23, 2021 09:54
@adrian-gierakowski
Copy link
Contributor

Any reason not to keep using jest?

@gvko
Copy link
Contributor Author

gvko commented Apr 23, 2021

Any reason not to keep using jest?

@adrian-gierakowski , yes, it runs very slowly.
Builds are running 10+ min cuz of slow tests.
Same case when we run the tests locally. I've made some isolated test suites comparison and with mocha they run 20+ times faster than with jest 🤷‍♂️

@adrian-gierakowski
Copy link
Contributor

Builds are running 10+ min cuz of slow tests.
Same case when we run the tests locally. I've made some isolated test suites comparison and with mocha they run 20+ times faster than with jest

Jest runs each test file in a sandbox (in a worker process), which brings a lot of benefits (like ability to run tests in parallel), but which also means any imports and setup code will run from scratch for each test file which makes the startup time a bit slower. Most of the time this is not a problem but I believe the massive slowdown compared to mocha you are seeing might be caused by repeated initialisation of some web3 related code (mocha would only run this once, while jest does once per test file). I wonder if we could identify the code which is slowing the tests down and find a solution which would allow us to keep using jest?

@adrian-gierakowski
Copy link
Contributor

there is no way to share modules/instances between tests, not event within a single worker

see:
jestjs/jest#7184 (comment)
jestjs/jest#8708

I believe there is a hack which allows to share strings from global setup to tests via process.env, but I don't think that would help here

2 possible solutions:

  1. mock the stuff that takes so long to initialise in most tests
  2. run tests in a single worker by creating in index file which requires all individual test files and passing that index file as an argument to jest (instead of letting it find all tests files)

@arijoon arijoon closed this Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants